The language and its core ecosystem. Not the data stack — that lives in ai-ml/00-foundations — and not the web frameworks, which live in backend/frameworks/python/ per the rule.
~18,800 words across 19 notes. Built August 2026, extended the same week after a roadmap.sh audit. [reference].
The one idea: Python trades machine time for programmer time, and every quirk in this course is that trade showing through. Names bind to objects (so assignment aliases), types are checked at runtime (so errors reach production), and one lock protects the interpreter (so threads don’t parallelise). Knowing why turns a list of gotchas into one model.
Why this exists
index listed “Python at depth” as a track that would slot in if notes got written. They hadn’t been — despite Python appearing throughout the vault: the entire ML domain is written in it, devops assumes it for automation, and programming fundamentals uses it for most examples.
So the vault taught Python-the-tool everywhere and Python-the-language nowhere. This closes that.
Reading order
01–04 are the model and are worth reading in order. 05–11 are the language’s features and can be dipped into. 12–14 are the runtime, and assume the rest.
Self-study pilot: Iterators, Generators and Laziness now has a state trace, runnable examples, and independent implementation checks. Follow its prerequisites and complete its local practice before moving on; you do not need to wait until note 18 to start practising. The remaining lessons have not yet received the same teaching-quality revision.
- Why Python, and the Toolchain — [Beginner] — what it’s for, versions, and virtual environments, which is where beginners lose days
- The Data Model — [Beginner → Intermediate] — names bind to objects;
isvs==, copying, truthiness, and the mutable default argument - Built-in Types and Collections — [Beginner] — str/list/dict/set costs, comprehensions, and the
collectionstypes that are usually the better answer - Functions and Scope — [Beginner → Intermediate] —
*args/**kwargs, LEGB, closures, and the late-binding trap - Classes and the Object Model — [Intermediate] — dunder methods as protocols, properties, dataclasses, the MRO
- Iterators, Generators and Laziness — [Intermediate] — the protocol behind every
for, and processing a file bigger than RAM - Decorators and Context Managers — [Intermediate] — the two idioms every real codebase uses
- Typing and Type Hints — [Intermediate] — gradual typing,
Protocol, narrowing, and how to adopt it without a revolt - Errors and Exceptions — [Intermediate] — EAFP, the hierarchy, chaining, and why
except: passis the worst line in Python - Modules, Packages and Imports — [Intermediate] — how resolution works, circular imports, and why
src/layout - The Standard Library — [Intermediate] — what’s already there, and what’s been superseded
- Concurrency and the GIL — [Advanced] — why threads don’t speed up computation, choosing between the three models, and PEP 703
- Testing and Tooling — [Intermediate] — pytest, fixtures,
parametrize, ruff, and the pre-commit/CI split - Performance and the Runtime — [Advanced] — why it’s slow, and the ordered list of what to try
15–17 were added after auditing this course against the roadmap.sh Python track — all three were named as gaps by the honest note below before the audit confirmed them.
- Files and I/O — [Beginner → Intermediate] — modes, encodings, large files, the atomic-write pattern, and path traversal
- Regular Expressions — [Intermediate] — the syntax worth memorising,
fullmatchvsmatch, and catastrophic backtracking as a DoS class - asyncio in Depth — [Advanced] — TaskGroups, cancellation, timeouts, bounding fan-out, and why sequential
awaits aren’t concurrent
Then the reps.
- Practice Exercises — [Beginner → Advanced] — eighteen exercises that reproduce the gotchas rather than describing them: the small-int cache, the mutable default,
UnboundLocalError, late binding, generator exhaustion, ReDoS, the GIL, the blocked event loop - Solutions — every number measured on Python 3.14, not estimated
The things worth carrying
- Assignment binds a name; it never copies. Whether you notice depends only on whether the object is mutable → 02
- Default arguments are evaluated once, at definition. Hence
def f(x, acc=[])is broken → 02 isis forNone,True,Falseand nothing else → 02x in listis O(n);x in setis O(1). Inside a loop that’s the whole performance story → 03Counter,defaultdictanddequeremove most hand-written dictionary and queue code → 03- Assigning to a name anywhere in a function makes it local everywhere in that function → 04
- Closures capture the variable, not its value → 04
- Behaviour is opted into by implementing dunder methods, not by declaring an interface. Always define
__repr__→ 05 - Properties are why Python has no getters and setters — you can convert an attribute later without breaking callers → 05
- A generator is consumed once. The commonest generator bug, and it shows up as an empty result far from the cause → 06
@functools.wrapsor your tracebacks all saywrapper→ 07- Type hints are ignored at runtime. Validate at the boundary anyway → 08
- EAFP beats LBYL because the check-then-act version has a race → 09
raise ... from e, andlog.exception()inside a handler → 09- A circular import is a design signal, not a syntax problem → 10
secrets, neverrandom, for anything an attacker would like to guess → 11- The GIL is released during I/O. Threads are useless for computation and excellent for waiting → 12
- One blocking call freezes the entire event loop → 12
parametrizeis the highest-return pytest feature — it makes edge cases cheap enough to actually write → 13- Coverage measures what ran, not what was checked → 13
- Fix the algorithm, then the I/O, then vectorise. Measure between each → 14
open(path, "w")truncates before you write anything. Atomic write = temp file, fsync,os.replace→ 15- Always pass
encoding="utf-8"— the default is platform-dependent, so it works locally and breaks in production → 15 re.matchanchors at position 0; it does not mean “does this match”. Usefullmatch→ 16- Nested quantifiers are a denial-of-service vector, and have taken down Cloudflare and Stack Overflow → 16
- Sequential
awaits are not concurrent.TaskGrouporgatheris what overlaps them → 17 - Every network call needs a timeout; every fan-out needs a semaphore → 17
Where this connects
| backend/frameworks/python/ | FastAPI, Django, Flask — the frameworks, per the languages/ rule |
| Python for data | NumPy, pandas, matplotlib — the numeric stack |
| programming fundamentals | If this is your first language, start there |
| bash scripting | When a shell script should have been Python |
| Go · Rust | The other end of the trade — types and concurrency enforced |
| compilers | What “bytecode on a VM” means |
Against the roadmap
Audited against the roadmap.sh Python track (August 2026). Its topic list maps onto this vault in three ways:
Covered here — basics and syntax, variables and types, conditionals, loops, functions, lambdas, scope, lists/tuples/sets/dictionaries, comprehensions, generator expressions, iterators, decorators, context managers, classes, inheritance, encapsulation, OOP, paradigms, exceptions, modules, package managers (pip/uv/poetry/pipenv/pdm/conda/pyenv/virtualenv), pyproject.toml, PyPI, static typing, type annotations, mypy/pyright, testing, pytest, unittest, ruff, black, code formatting, the GIL, threading, multiprocessing, concurrency, asynchrony, file handling, glob, regular expressions, string handling, type casting.
Covered elsewhere in this vault, deliberately not duplicated:
| Roadmap topic | Where it lives |
|---|---|
| Data structures & algorithms, sorting, arrays, linked lists, hashmaps, heaps/stacks/queues, BSTs, recursion | foundations/dsa/ |
| Django, Flask, FastAPI, Pydantic | backend/frameworks/python/ — per the languages/ rule |
| NumPy, pandas, plotting | ai-ml/00-foundations |
| Git, clean code, paradigms | git/, best practices, paradigms |
Deliberately skipped — the alternative-framework long tail (Tornado, Sanic, Pyramid, aiohttp, gevent, Plotly Dash), the formatter/doc long tail (yapf, sphinx, doctest, tox, pyre). These are lookups, not understanding, and listing them would imply coverage that adds nothing over their own documentation.
The honest note
[reference], but less so than most of this vault — Python is the language I actually reach for, and the ML domain and assorted automation are written in it. What’s read-not-lived is specifically: the free-threaded build, PyPy, Cython/PyO3, and multiprocessing at any real scale.
What would close the gap:
- Reproduce the mutable-default and late-binding traps in a REPL. Two minutes, and notes 02 and 04 stop being warnings and become memories
- Profile something real with
cProfile, thenline_profileron the hot function. Then fix it and measure again. Note 14 is worthless without the second measurement - Take one loop and vectorise it with NumPy. Time both. The 10–100× is the claim; verify it
- Add
mypyto one existing module and count what it finds. That number is the argument for note 08 - Write a decorator with arguments from scratch, without copying. Three levels of nesting is the part that doesn’t stick from reading
- Benchmark
threadingvsmultiprocessingon one CPU-bound and one I/O-bound task. Note 12’s table, verified in ten minutes
What’s missing: (closed, note 17), metaclasses and descriptors (deliberately — rarely needed, frequently misused), packaging as a publisher (building and uploading to PyPI), and C-extension authoring. asyncio at depthExercises — closed by notes 18–19 (Aug 2026).
Related
- languages/ — the domain index
- Python backends
- Build Plan
Software engineering
Infrastructure & security
Computer science
Hardware & engineering