A cheat sheet does not teach you Python. It saves you from forgetting the syntax while you practise. Here is a one-page Python cheat sheet for beginners. Print it (use your browser's Save as PDF if you prefer a file), and keep it next to you while you code.
Direct answer
The core of beginner Python is variables, strings, lists, dictionaries, conditions, loops, functions and files. The sections below show each with the syntax you need.
Variables and data types
name = "Ada" # string (str)
age = 30 # integer (int)
price = 4.99 # float
is_ready = True # boolean (bool)
type(age) # <class 'int'>
Maths
10 + 3 # 13
10 - 3 # 7
10 * 3 # 30
10 / 3 # 3.333... (always a float)
10 // 3 # 3 (whole number division)
10 % 3 # 1 (remainder)
2 ** 3 # 8 (power)
Strings
s = "hello world"
len(s) # 11
s.upper() # "HELLO WORLD"
s.title() # "Hello World"
s.replace("l", "L") # "heLLo worLd"
s.split(" ") # ["hello", "world"]
s[0] # "h"
s[0:5] # "hello"
f"Hi {name}, you are {age}" # f-string
Input and output
answer = input("Your name? ") # always a string
n = int(input("A number: ")) # convert to a number
print("Hello", answer)
Conditions
if age >= 18:
print("adult")
elif age >= 13:
print("teen")
else:
print("child")
# comparisons: == != < > <= >=
# logic: and or not
Lists
fruits = ["apple", "pear"]
fruits.append("plum") # add to end
fruits.remove("pear") # remove by value
fruits[0] # first item
fruits[-1] # last item
len(fruits) # how many
"apple" in fruits # True
sorted([3, 1, 2]) # [1, 2, 3]
Dictionaries
person = {"name": "Ada", "age": 30}
person["name"] # "Ada"
person["city"] = "Paris" # add or change
person.get("job", "n/a") # "n/a" if missing
for key, value in person.items():
print(key, value)
Loops
for i in range(5): # 0 to 4
print(i)
for fruit in fruits:
print(fruit)
n = 3
while n > 0:
print(n)
n -= 1
# break = leave the loop, continue = skip to the next round
Functions
def add(a, b=0):
return a + b
add(2, 3) # 5
add(2) # 2
Files
with open("notes.txt", "w") as f:
f.write("hello\n")
with open("notes.txt") as f:
text = f.read()
Errors
try:
n = int(input("Number: "))
except ValueError:
print("That was not a number")
Handy built-ins
| Function | What it does |
|---|---|
len(x) | length of a string, list or dictionary |
range(n) | numbers from 0 to n-1 |
sum(list) | add up a list of numbers |
min(list), max(list) | smallest, largest |
sorted(list) | a new sorted list |
round(x, 2) | round to 2 decimals |
type(x) | the data type |
Common beginner errors
- IndentationError: the spaces at the start of a line do not match. Use four spaces.
- NameError: you used a name you have not defined (often a typo).
- TypeError: mixing types, such as adding a string and a number. Convert with
int()orstr(). - SyntaxError: a missing colon, bracket or quote.
How to use this sheet
Keep it open, but do not copy and paste. Type each snippet, change the values, and predict the result before you run it. For a practice plan, see learn Python in 30 days, and for a project list, Python projects for beginners.
The bottom line
A cheat sheet is a memory aid. The skill comes from writing code every day. The Python for Beginners course gives you short lessons with real code to run, free to start.



