Python Basics
Learn Python as a small set of interacting models, not a catalog of methods.
This section is a Python 3.10+ reference for small synchronous programs: names and
objects, functions and control flow, strings and collections, classes, and local
files. It does not cover packaging, asynchronous execution, concurrency, or the
full standard library. Start with syntax, then functions, conditionals, and loops;
read lists and classes before the tree example in recursion. Code with undefined
names such as process is an API pattern, not a standalone script. Complete
examples include their inputs and assertions; assertions are learning checks,
not input validation, since Python can disable them with -O.
Learning path
Core mental model
- Variables are names bound to objects; assignment does not copy an object.
- Every object has a type, identity, and value.
- Mutability determines whether an object can change; the operation's contract determines whether it actually mutates or returns a result.
- Iteration asks an iterable for values; it is not limited to numeric indexes.
- Exceptions communicate failures across call boundaries.
- Modules and packages create namespaces and reusable ownership boundaries.
Working rules
- Prefer clear data flow and small functions over clever expression density.
- Make mutation and I/O visible at boundaries.
- Use standard-library types and protocols before inventing wrappers.
- Add annotations to communicate contracts, then use tooling if enforcement is required; Python does not enforce most annotations by itself.
- Test behavior rather than copying interpreter output into notes.