Python programs operate on objects with explicit input, ownership and failure contracts.
Learning roadmap
This section contains 39 written lessons or quiz banks. Programs are verified on CPython 3.14.6. Standard-library lessons target 3.11+ syntax; lessons using data, web, machine-learning or testing packages state their tested dependencies separately. Framework programs use local test clients, not a deployed service. Read the stated limits before adapting a fixture into an application.
Interpreter and values
Read the contract, run its program and inspect the failure case.
- Python interpreter and virtual environments: run the intended executable
- Python variables: names refer to objects, assignment does not copy
- Python numeric operators: division, floor division and remainder contracts
- Python conditions and loops: distinguish no value from an empty value
- Python match statements: shape matching is not input validation
Functions and failures
Read the contract, run its program and inspect the failure case.
- Python functions: define units, validate input and return a result
- Python function arguments: avoid shared mutable defaults
- Python exceptions: translate an input error without hiding its cause
- Python modules: separate import-time definitions from program execution
- Python string formatting: format text without building SQL syntax
- Python type hints: annotations do not enforce runtime arguments
Sequence expressions
Read the contract, run its program and inspect the failure case.
- Python comprehensions: build results without changing the input
- Python list slicing: half-open ranges and shallow ownership
Object state
Read the contract, run its program and inspect the failure case.
- Python classes: keep instance state separate from class state
- Python inheritance: override behavior without inventing shared ownership
- Python properties: validate mutation at the public attribute boundary
Scope and call boundaries
Read the contract, run its program and inspect the failure case.
- Python scope: local assignment, nonlocal state and late binding
- Python unpacking: keyword collisions and strict record pairing
Bounded nested input
Read the contract, run its program and inspect the failure case.
Input, iteration and function tools
Read the contract, run its program and inspect the failure case.
- Python input and output: separate parsing from terminal I/O
- Python truth values: distinguish missing data from valid zero
- Python type conversion: parsing success is not field validity
- Python break, continue and loop else: encode the stopping condition
- Python range and enumerate: indexes are not stable record identities
- Python lambda functions: one expression and the same closure rules
- Python map, filter and reduce: iterator timing and reduction identity
- Python staticmethod and classmethod: choose the bound receiver
Source names, callable dispatch and preserved startup contracts
Read the contract, run its program and inspect the failure case.
- Python keywords and identifiers: parser rules differ from field rules
- Python first-class functions: dispatch through an explicit operation registry
- Python refactoring: preserve rejected inputs as well as accepted results
- Python import failures: module removal does not roll back every side effect
Stable rejection and explicit calls
Read the contract, run its program and inspect the failure case.
- Python assert versus input validation: optimized execution changes the contract
- Python positional-only and keyword-only parameters: keep call roles explicit
Unpacking and evaluation
Read the contract, run its program and inspect the failure case.
- Python starred unpacking: allocate the middle and reject wrong arity
- Python comparison chains: the middle operand is evaluated once
- Python module cache: repeated imports reuse an owned module object
- Python assignment expressions: capture a checked value once
Pull loops and sentinels
Read the contract, run its program and inspect the failure case.
Strictly paired feeds
Read the contract, run its program and inspect the failure case.
Continue learning
Move between tutorial, collections, advanced material and practice using the subject tabs. The sidebar changes with each section; related examples keep one canonical lesson URL.
