Course 15 · Craft
Python
A second language, properly.
Real CPython, running in this page — from the first print to generators, dataclasses and decorators, with every exercise executed by the interpreter itself.
0 of 24 lessons finished — nothing yet
The syllabus
24 lessons,
in the order they build on each other.
Running Python
The interpreter, print, and the one thing about indentation that surprises everybody.
Values and types
Numbers, strings, booleans and None — dynamic typing, and what counts as true.
Strings
Slicing, methods, f-strings, and why a string can never be changed.
Lists
Order, mutation, and the difference between another name and another list.
Tuples and sets
Unpacking, immutability, membership in constant time, and what may be hashed.
Dictionaries
The structure Python is built out of: lookups, defaults, grouping and counting.
Control flow
if / elif / else, while, for, and the loop-else clause almost nobody knows.
Comprehensions
The one-line loop that builds a list, a dict, a set — or nothing at all, lazily.
Functions
Arguments, defaults, *args and **kwargs — and the mutable default that bites everyone once.
Scope and closures
LEGB, global and nonlocal, and the loop that captures the wrong variable.
Errors and exceptions
try / except / else / finally, raising your own, and asking forgiveness rather than permission.
Modules and packages
import, __name__, the search path, and writing a module you can then import.
Files and paths
with open, text against bytes, encodings, pathlib, JSON and CSV.
Classes
State and behaviour together: __init__, attributes, methods, and what self really is.
Special methods
__repr__, __eq__, __hash__, __len__ — how an object joins the language itself.
Dataclasses
The boilerplate Python writes for you, and when a NamedTuple is the better answer.
Iterators and generators
The protocol behind every for loop, and yield — a million rows in constant memory.
Functional Python
sorted with a key, any and all, lambda, reduce, partial and a cache in one line.
Decorators
A function that wraps a function: timing, caching and logging without touching the code.
Context managers
with, __enter__ and __exit__, and contextlib — cleanup that happens even when it goes wrong.
Type hints
Annotations Python does not enforce, a checker that does, and Protocol for duck typing.
The standard library
datetime, re, collections, itertools, math and random — batteries, actually included.
Testing in Python
unittest and pytest-shaped tests, fixtures, parametrising, and what to assert.
Practice: a log analyser
One messy log file, real Python: parse it, group it, and answer four questions about it.
Keep going
The other courses.
HTML
The document, the elements and the meaning behind them. Everything else on the web is layered on top of this.
CSS
Selectors, the box model, layout with flexbox and grid, and motion that has a reason to move.
JavaScript
Values, functions, the DOM, events and asynchronous work — written so you can debug it later.