Python
Essential Python reference covering syntax, data structures, functions, OOP, comprehensions, type hints, virtual environments, and the standard library.
Other Python Sheets
Setup & Basics
Install Python, run scripts, and understand basic syntax.
Installation & Running Python
Install Python and run scripts from the command line.
Variables & Data Types
Python variables are dynamically typed — no declaration keyword needed.
Strings & Formatting
String operations, methods, and formatting with f-strings.
String Operations
Common string methods and operations.
String Formatting
Format strings with f-strings, .format(), and % operator.
Control Flow
Conditionals, loops, match statements, and flow control keywords.
Conditionals
if/elif/else statements and ternary expressions.
Loops
for and while loops with break, continue, and else clauses.
Match Statements
Structural pattern matching (Python 3.10+).
Data Structures
Lists, tuples, dictionaries, and sets — with comprehensions.
Lists
Ordered, mutable sequences with powerful methods.
Dictionaries
Key-value mappings with fast lookups.
Tuples & Sets
Immutable sequences and unique unordered collections.
Comprehensions
Concise syntax for creating lists, dicts, and sets.
Functions
Define functions with default args, *args, **kwargs, and lambda expressions.
Function Basics
Define functions with parameters, defaults, and return values.
*args, **kwargs & Unpacking
Accept variable arguments and unpack iterables into function calls.
Lambda & Higher-Order Functions
Anonymous functions and built-in functions that take functions as arguments.
Classes & OOP
Classes, inheritance, dataclasses, and special methods.
Class Basics
Define classes with __init__, instance methods, and class/static methods.
Inheritance & Dataclasses
Extend classes with inheritance and use dataclasses for data containers.
Error Handling
Handle exceptions with try/except, raise errors, and define custom exceptions.
Try / Except / Finally
Catch and handle exceptions gracefully.
File I/O
Read and write files, work with JSON, and use context managers.
File Operations & JSON
Read, write, and append files. Parse and write JSON data.
Modules & Virtual Environments
Import modules, create packages, and manage dependencies with venv and pip.
Imports & Modules
Import standard library and custom modules.
Virtual Environments & pip
Isolate project dependencies with virtual environments.
Type Hints
Add type annotations for better code clarity and tooling support.
Type Annotations
Annotate function parameters, return types, and variables.
Advanced Features
Decorators, generators, context managers, and the walrus operator.
Decorators
Wrap functions to add behavior without modifying the original.
Generators & Context Managers
Lazy iteration with yield and resource management with "with" statements.
Standard Library
Essential modules from the Python standard library.
Essential Modules
Most commonly used standard library modules.
Best Practices
Pythonic patterns and performance tips.
Pythonic Patterns
Write idiomatic Python code.