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.

  1. Why Python, and the Toolchain — [Beginner] — what it’s for, versions, and virtual environments, which is where beginners lose days
  2. The Data Model — [Beginner → Intermediate] — names bind to objects; is vs ==, copying, truthiness, and the mutable default argument
  3. Built-in Types and Collections — [Beginner] — str/list/dict/set costs, comprehensions, and the collections types that are usually the better answer
  4. Functions and Scope — [Beginner → Intermediate] — *args/**kwargs, LEGB, closures, and the late-binding trap
  5. Classes and the Object Model — [Intermediate] — dunder methods as protocols, properties, dataclasses, the MRO
  6. Iterators, Generators and Laziness — [Intermediate] — the protocol behind every for, and processing a file bigger than RAM
  7. Decorators and Context Managers — [Intermediate] — the two idioms every real codebase uses
  8. Typing and Type Hints — [Intermediate] — gradual typing, Protocol, narrowing, and how to adopt it without a revolt
  9. Errors and Exceptions — [Intermediate] — EAFP, the hierarchy, chaining, and why except: pass is the worst line in Python
  10. Modules, Packages and Imports — [Intermediate] — how resolution works, circular imports, and why src/ layout
  11. The Standard Library — [Intermediate] — what’s already there, and what’s been superseded
  12. Concurrency and the GIL — [Advanced] — why threads don’t speed up computation, choosing between the three models, and PEP 703
  13. Testing and Tooling — [Intermediate] — pytest, fixtures, parametrize, ruff, and the pre-commit/CI split
  14. 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.

  1. Files and I/O — [Beginner → Intermediate] — modes, encodings, large files, the atomic-write pattern, and path traversal
  2. Regular Expressions — [Intermediate] — the syntax worth memorising, fullmatch vs match, and catastrophic backtracking as a DoS class
  3. asyncio in Depth — [Advanced] — TaskGroups, cancellation, timeouts, bounding fan-out, and why sequential awaits aren’t concurrent

Then the reps.

  1. 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
  2. Solutions — every number measured on Python 3.14, not estimated

The things worth carrying

  1. Assignment binds a name; it never copies. Whether you notice depends only on whether the object is mutable → 02
  2. Default arguments are evaluated once, at definition. Hence def f(x, acc=[]) is broken → 02
  3. is is for None, True, False and nothing else → 02
  4. x in list is O(n); x in set is O(1). Inside a loop that’s the whole performance story → 03
  5. Counter, defaultdict and deque remove most hand-written dictionary and queue code → 03
  6. Assigning to a name anywhere in a function makes it local everywhere in that function → 04
  7. Closures capture the variable, not its value → 04
  8. Behaviour is opted into by implementing dunder methods, not by declaring an interface. Always define __repr__ → 05
  9. Properties are why Python has no getters and setters — you can convert an attribute later without breaking callers → 05
  10. A generator is consumed once. The commonest generator bug, and it shows up as an empty result far from the cause → 06
  11. @functools.wraps or your tracebacks all say wrapper → 07
  12. Type hints are ignored at runtime. Validate at the boundary anyway → 08
  13. EAFP beats LBYL because the check-then-act version has a race → 09
  14. raise ... from e, and log.exception() inside a handler → 09
  15. A circular import is a design signal, not a syntax problem → 10
  16. secrets, never random, for anything an attacker would like to guess → 11
  17. The GIL is released during I/O. Threads are useless for computation and excellent for waiting → 12
  18. One blocking call freezes the entire event loop → 12
  19. parametrize is the highest-return pytest feature — it makes edge cases cheap enough to actually write → 13
  20. Coverage measures what ran, not what was checked → 13
  21. Fix the algorithm, then the I/O, then vectorise. Measure between each → 14
  22. open(path, "w") truncates before you write anything. Atomic write = temp file, fsync, os.replace → 15
  23. Always pass encoding="utf-8" — the default is platform-dependent, so it works locally and breaks in production → 15
  24. re.match anchors at position 0; it does not mean “does this match”. Use fullmatch → 16
  25. Nested quantifiers are a denial-of-service vector, and have taken down Cloudflare and Stack Overflow → 16
  26. Sequential awaits are not concurrent. TaskGroup or gather is what overlaps them → 17
  27. 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 dataNumPy, pandas, matplotlib — the numeric stack
programming fundamentalsIf this is your first language, start there
bash scriptingWhen a shell script should have been Python
Go · RustThe other end of the trade — types and concurrency enforced
compilersWhat “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 topicWhere it lives
Data structures & algorithms, sorting, arrays, linked lists, hashmaps, heaps/stacks/queues, BSTs, recursionfoundations/dsa/
Django, Flask, FastAPI, Pydanticbackend/frameworks/python/ — per the languages/ rule
NumPy, pandas, plottingai-ml/00-foundations
Git, clean code, paradigmsgit/, 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:

  1. Reproduce the mutable-default and late-binding traps in a REPL. Two minutes, and notes 02 and 04 stop being warnings and become memories
  2. Profile something real with cProfile, then line_profiler on the hot function. Then fix it and measure again. Note 14 is worthless without the second measurement
  3. Take one loop and vectorise it with NumPy. Time both. The 10–100× is the claim; verify it
  4. Add mypy to one existing module and count what it finds. That number is the argument for note 08
  5. Write a decorator with arguments from scratch, without copying. Three levels of nesting is the part that doesn’t stick from reading
  6. Benchmark threading vs multiprocessing on one CPU-bound and one I/O-bound task. Note 12’s table, verified in ten minutes

What’s missing: asyncio at depth (closed, note 17), metaclasses and descriptors (deliberately — rarely needed, frequently misused), packaging as a publisher (building and uploading to PyPI), and C-extension authoring. Exercises — closed by notes 18–19 (Aug 2026).

→ Reading is not a rank.

↑ Back to Languages