Skip to main content
Python Basics2026-11-01 · 8 min read

Python Cheat Sheet 2026: The One Page Every Python Dev Should Print

You know the feeling: you wrote a loop yesterday, today you cannot remember whether it is elif or else if. That is normal. Nobody keeps the whole language in their head, and good developers lean on a short reference all the time. This page is that reference: the small core of Python that shows up in almost every real script, in the order you will need it.

Bookmark it, print it, tape it next to the monitor. If you want the full interactive version, there is a Python cheat sheet on the site you can search while you code.

Data types and literals

▶ PYTHONeditable · runs in your browser

Quick rule of thumb: need order and changes, use a list. Need lookup by name, use a dict. Need to remove duplicates, use a set. Need something that must not change, use a tuple.

Control flow

▶ PYTHONeditable · runs in your browser

Remember that Python uses indentation instead of braces. Four spaces per level, never mix tabs and spaces.

f-strings and format specs

▶ PYTHONeditable · runs in your browser

Comprehensions

▶ PYTHONeditable · runs in your browser

If a comprehension needs more than one condition and a nested loop, write a normal for loop instead. Readable beats clever.

Error handling

▶ PYTHONeditable · runs in your browser

Catch the specific error you expect. A bare except: hides real bugs.

The with statement and context managers

▶ PYTHONeditable · runs in your browser

Use with for files, database connections, locks, anything that must be released.

Functions and classes

▶ PYTHONeditable · runs in your browser

A @dataclass writes __init__, __repr__ and __eq__ for you. Reach for it before writing a class by hand.

If you want to practice functions and classes interactively in the browser, try the foundations course: every step runs real Python and checks your answer.

File input and output

▶ PYTHONeditable · runs in your browser

pathlib replaces most of the old os.path string juggling. It also handles Windows and macOS separators for you.

Imports

▶ PYTHONeditable · runs in your browser

Handy standard library

▶ PYTHONeditable · runs in your browser

Dictionary tricks you will use weekly

▶ PYTHONeditable · runs in your browser

Common mistakes this sheet will save you from

  • Using a mutable default argument such as def f(items=[]). Use None and create the list inside.
  • Comparing with is instead of == for values. Use is only for None.
  • Forgetting that range(5) stops at 4.
  • Changing a list while looping over it. Loop over a copy or build a new list.

How to actually learn it, not just read it

A cheat sheet helps you remember, but you only learn by typing. Pick three snippets from this page, close it, and rewrite them from memory. Then run them. When you get stuck, look, close the tab, try again. Ten minutes of that beats an hour of rereading.

When you are ready to go from snippets to real exercises, start the free beginner lessons and keep this page open beside them. The searchable Python cheat sheet is always one click away.

FAQ

What should be on a Python cheat sheet? The core types, control flow, f-strings, comprehensions, error handling, with, functions, classes, file input and output, imports and a few standard library tools. That is the small set used in most real code.

Is a cheat sheet enough to learn Python? No. It is a memory aid. You still need to write programs and fix your own mistakes to make the syntax stick.

Which Python version does this cover? Everything here works on current Python 3 releases. The dataclass and f-string = forms need Python 3.8 or newer.

Should I use pathlib or os.path? Prefer pathlib for new code. It is shorter, readable and cross-platform.

List or tuple, which one? Use a list when the contents change and a tuple when they should stay fixed, such as coordinates.

Where can I practice these snippets? In the browser, with no install, in the free lessons on this site.

Ready to try it?

15 lessons free after a free signup — no card. Sample the platform, then decide.

Start free →

Or unlock every lesson

Pro — $12/mo, unlimited AI, cancel any time. Refund within 14 days worldwide.

See Pro plans →

Get one Python lesson + one career idea every Friday

No spam, no "buy our course now". Three bullets, every Friday. Unsubscribe with one click.