Python is readable, but nobody memorizes every built-in method. The useful approach is to learn the patterns that repeat across almost every program, then keep a reference for the details. The Printable Python Beginner Cheatsheet is organized around exactly those patterns across four pages. This guide walks through the same topics with examples you can run.
Variables, numbers and strings
Python infers types, so you can assign and reuse names freely. f-strings are the fastest way to combine text and values:
name = "Ana"
score = 92.5
print(f"{name} scored {score:.1f}") # Ana scored 92.5
print(round(score)) # 92
print(" hello ".strip().upper()) # HELLO
Operators to know early: // for integer division, % for remainders, and ** for powers.
Lists and dictionaries
Lists hold ordered items, and dictionaries map keys to values. Use .get() on dictionaries to avoid errors when a key might be missing:
fruits = ["apple", "pear"]
fruits.append("plum")
print(fruits[0], fruits[-1]) # apple plum
print(fruits[1:3]) # ['pear', 'plum']
scores = {"ana": 90, "ben": 75}
print(scores.get("cara", 0)) # 0, no KeyError
Tuples are fixed after creation, which makes them good for values that should not change. Sets remove duplicates and support .union() and .intersection().
Loops, conditions and functions
for i, fruit in enumerate(fruits):
print(i, fruit)
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Ben")) # Hello, Ben!
Use enumerate() whenever you need both the index and the item. Default arguments, as in greeting="Hello", let callers skip optional values.
Reading and writing files
The with statement closes the file automatically, even if an error occurs:
with open("notes.txt", "w") as f:
f.write("First line\n")
with open("notes.txt", "r") as f:
text = f.read()
Use "a" mode to append instead of overwrite.
Handling errors
try:
value = int("abc")
except ValueError:
print("That is not a number.")
else:
print("Converted:", value)
finally:
print("Done.")
Catch specific exceptions, such as ValueError, rather than every error. A broad catch can hide bugs.
Modules and basic classes
Built-in modules such as math, random, os and sys are imported with a single line. For object-oriented work, start with __init__ and self:
import math
class Circle:
def __init__(self, radius):
self.radius = radius
def area(self):
return math.pi * self.radius ** 2
print(round(Circle(2).area(), 2)) # 12.57
A study routine that works
- Type each example yourself instead of copying it.
- Change one value and predict the output before running it.
- Keep the cheatsheet beside your keyboard and look up methods as you need them, not all at once.
If you want a printable version of these patterns, the Printable Python Beginner Cheatsheet packages them into four study pages. Related: how to choose and use a printable cheatsheet.
How to practise Python without a teacher
Reading about Python is pleasant, but understanding comes from typing code and watching it fail. The most effective way to practise is to take each example in a guide, change one value, and predict the result before you run it. If your prediction is wrong, the gap between expectation and output is where learning happens. Keep a short notes file with the surprises you encountered, because those notes become a personal reference that is more useful than any generic tutorial.
The cheatsheet works best as a companion to practice rather than a replacement for it. Keep it open beside your editor, look up a method when you need it, and resist the urge to memorise the whole page on the first day. Familiarity grows through repeated use, and a printed reference makes that repetition easier to sustain.
Reading error messages without panic
Almost every beginner meets a traceback in the first week, and the message can look alarming. Python tracebacks are written from the bottom up in terms of the most useful information: the last line names the error type, such as a NameError or a ValueError, and the lines above it show where the problem occurred. Read the error type first, then the line number, then the code on that line. Most beginner errors come from a small set of causes, including a misspelt variable name, a missing colon after a statement, mixing text and numbers without conversion, and forgetting that a method needs parentheses.
Choosing a first project that teaches the right things
A good first project uses several topics at once without becoming overwhelming. A budget calculator, a word counter, a simple quiz and a file-based to-do list are all suitable. Pick something you would actually use. Personal relevance keeps you returning to the project when the material gets harder, and it gives you a real test of whether your code works. Start with a version that does one thing, then add features one at a time.
What to learn after the basics
Once you are comfortable with variables, loops, functions and files, the next step is organising code into modules and learning how to test it. Reading other people's programs is also valuable. Choose a short script from a public repository, run it, and trace what each part does. This habit builds the reading skill that employers and collaborators rely on, and it is often neglected by people who only write their own code.
Object-oriented programming, which the cheatsheet introduces with classes, __init__ and self, becomes much easier after you have written several functions. Classes group related data and behaviour, and they become useful when a program has many similar objects, such as customers, transactions or game characters. You do not need classes for every script, so learn them when a project genuinely calls for them.
Reading code as well as writing it
Beginners often focus entirely on writing code and neglect reading it. Yet reading is how you absorb patterns that work. Pick a short example from a reputable tutorial or a public repository each week, read it line by line, and say out loud what each line does. Reading builds the pattern recognition that makes writing feel natural, and it prepares you for the far larger codebases you will meet later.
The four pages of the cheatsheet are a good map for this practice. Read one section, find a line of code that uses it, and explain it in your own words before moving on.
