PythonMastery
Cheat sheets

Python cheat sheets: free one-page PDFs

24 topics, each on a single A4 page you can print, pin above your desk or keep open next to your editor. 1263 examples in all, and every one is run against Python 3.13 before a sheet is published, so the result printed next to it is the result you'll get. Each sheet ends with the mistakes people often make.

Preview of the Python tuples cheat sheet

Python tuples

A tuple keeps values in order and cannot change after you create it.

One A4 page · 64 examples · PDF, 205 KB
Preview of the Python dictionaries cheat sheet

Python dictionaries

A dictionary (dict) stores each value under a key, so you can find a value quickly by its key.

One A4 page · 56 examples · PDF, 209 KB
Preview of the Python slicing cheat sheet

Python slicing

seq[start:stop:step] takes the items from index start up to, but not including, index stop, as a new list, string or tuple.

One A4 page · 49 examples · PDF, 223 KB
Preview of the Python comprehensions cheat sheet

Python comprehensions

A comprehension is a for loop, written in one line, that builds a new list, set or dict.

One A4 page · 49 examples · PDF, 209 KB
Preview of the Python loops cheat sheet

Python loops

A loop runs the same lines again: once for each item (for), or as long as a condition is true (while).

One A4 page · 31 examples · PDF, 224 KB
Preview of the Python functions cheat sheet

Python functions

A function is a named block of code that you can run again and again.

One A4 page · 35 examples · PDF, 231 KB
Preview of the Python classes cheat sheet

Python classes

A class is a plan for a kind of thing: what data it holds and what it can do.

One A4 page · 31 examples · PDF, 234 KB
Preview of the Python files and paths cheat sheet

Python files and paths

A Path is only a name until you read or write it, and text files should always be opened with encoding="utf-8" (the encoding is how letters are stored as bytes).

One A4 page · 61 examples · PDF, 237 KB
Preview of the Python JSON cheat sheet

Python JSON

JSON is a plain-text format for data (objects, lists, strings, numbers, true/false and null) that almost every language and web API can read.

One A4 page · 35 examples · PDF, 242 KB
Preview of the Python exceptions cheat sheet

Python exceptions

When an error happens, Python passes it back up through the function calls until an except for its class catches it.

One A4 page · 54 examples · PDF, 234 KB
Preview of the Python collections cheat sheet

Python collections

The collections module gives you ready-made containers for jobs that plain lists and dicts make awkward: counting, grouping, queues and small records.

One A4 page · 41 examples · PDF, 230 KB
Preview of the Python dates and times cheat sheet

Python dates and times

A date is a day, a datetime is a day plus a clock time, and a timedelta is a length of time: subtract two datetimes and you get a timedelta.

One A4 page · 67 examples · PDF, 211 KB
Preview of the Python regular expressions cheat sheet

Python regular expressions

A regular expression is a pattern that describes text.

One A4 page · 58 examples · PDF, 229 KB
Preview of the Python itertools cheat sheet

Python itertools

Every tool here is lazy: it makes one item at a time, only when a loop asks for the next item.

One A4 page · 54 examples · PDF, 205 KB
Preview of the Python argparse cheat sheet

Python argparse

argparse reads the words typed after your script's name, turns them into values of the right type, and writes the help and error messages for you.

One A4 page · 59 examples · PDF, 214 KB
Preview of the pip and virtual environments cheat sheet

pip and virtual environments

pip installs packages that other people wrote.

One A4 page · 50 examples · PDF, 213 KB
Preview of the NumPy arrays cheat sheet

NumPy arrays

A NumPy array is a grid of numbers of one type that you can do maths on all at once, with no loop.

One A4 page · 46 examples · PDF, 230 KB
Preview of the pandas cheat sheet

pandas

pandas works with tables of data, like a spreadsheet inside Python.

One A4 page · 46 examples · PDF, 217 KB

Free to share, not to sell. Print them for yourself, your class or your team, and share the files as they are. Each sheet links to its runnable version on this site, where you can try every example in the browser.