The Python Basics Cheat Sheet for Beginners
TL;DR
Python is the friendliest first language, and its core fits on a page. Learn variables, the basic types, if/for, functions, and lists and dictionaries, and you can read and write most beginner Python. Keep this open while you build.
Why Python first
Python reads almost like English, which is exactly why it is the most recommended first language. There is very little punctuation to fight, the rules are consistent, and it is used everywhere - from automating small tasks to data work to full web apps. Learn the handful of ideas below and you can start building real things.
Variables and the basic types
- A variable is a named box for a value: name = "Sam"
- String - text, in quotes: greeting = "hello"
- Integer - a whole number: age = 30
- Float - a decimal number: price = 9.99
- Boolean - true or false: is_ready = True
- You do not declare the type - Python figures it out from the value.
pythonname = "Sam"
age = 30
print("Hello,", name) # Hello, Sam
print(age + 1) # 31Making decisions and repeating
python# if / else
if age >= 18:
print("adult")
else:
print("minor")
# for loop
for n in range(3):
print(n) # 0, 1, 2Functions - reusable blocks
pythondef greet(name):
return "Hello, " + name
message = greet("Sam")
print(message) # Hello, SamLists and dictionaries
- A list is an ordered collection: fruits = ["apple", "pear"]. Get the first with fruits[0].
- A dictionary is labeled data - keys and values: user = {"name": "Sam", "age": 30}. Get a value with user["name"].
- Loop over a list with 'for fruit in fruits:' and over a dictionary's items with 'for key, value in user.items():'.
pythonfruits = ["apple", "pear", "plum"]
for fruit in fruits:
print(fruit)
user = {"name": "Sam", "age": 30}
print(user["name"]) # SamRunning your code
Save your code in a file ending in .py, then run it from the terminal with 'python filename.py' (or 'python3 filename.py' on some systems). That is the whole loop: write, save, run, see the output, adjust.
Common questions
Is Python really the best first language?
For most beginners, yes. It reads close to plain English, has simple and consistent rules, and is used across automation, data, and web work - so the skills transfer widely. That combination makes it the most commonly recommended starting point.
Why does Python care so much about spaces at the start of lines?
Python uses indentation instead of braces to know what code belongs inside an if statement or loop. Keeping it consistent - four spaces per level is standard - prevents the most common beginner errors. Your editor can handle this automatically.
How do I actually run a Python file?
Save it with a .py ending, open a terminal in that folder, and run 'python filename.py' (or 'python3 filename.py' on some systems). It runs the code and prints any output. Write, save, run, adjust - that loop is the core of learning.
What is the difference between a list and a dictionary?
A list is an ordered collection you reach into by position (the first item, the second). A dictionary stores labeled data as key-value pairs, so you reach in by name. Use a list for a sequence of things, a dictionary when each value needs a label.
Get the Python basics cheat sheet
Get 650+ plug-and-play skills, MCPs & prompts, plus 5,000+ builders - $9/mo, cancel anytime.
Join the Club