Python Cheat Sheet
|
This section documents the current Python release line as published at the official Python documentation, which is the reference these pages are written and verified against. No specific patch version is pinned. This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
A single-page, colour-coded summary of the Python essentials — the install and run one-liners, the core types
and mutability model, string formatting with f-strings, collection literals and comprehension syntax, control
flow including match, function signature forms (args/*kwargs///*) and the LEGB rule, the iterator/
generator protocol, module and package layout, the with statement and pathlib,
try/except/else/finally/raise from, class syntax and the common dunder methods grouped by purpose,
super()/MRO, @property, decorator syntax, the type-hint syntax cheatsheet, @dataclass and Enum, a short
standard-library index, asyncio async/await syntax, venv/pip commands, and a pytest block (fixtures,
parametrization, mock/patch syntax) — handy for quick memorization or as a printable desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Getting started — Getting Started with Python.
Core language — Lexical Structure and Style, Variables and Dynamic Typing, Numbers, Strings and Text, Collections, Control Flow, Functions, Iterators, Generators and Comprehensions, Modules and Packages, Files and Context Managers, and Exceptions.
Object-oriented programming — Classes and Objects, Operator Overloading, Advanced OOP Design, Managed Attributes, and Decorators and Metaclasses.
Modern Python & standard library — Type Hints, Dataclasses and Enums, Standard Library Tour, Concurrency and Async, Virtual Environments and Packaging, and Debugging and Tooling.
Testing — Unit Testing with pytest & Mocking.