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.

24Lessons
≈ 5hReading
24Playable now
SyntaxData structuresClassesGeneratorsStandard library

0 of 24 lessons finished — nothing yet

The syllabus

24 lessons,
in the order they build on each other.

Start lesson one ↗
01

Running Python

The interpreter, print, and the one thing about indentation that surprises everybody.

≈ 10 min
02

Values and types

Numbers, strings, booleans and None — dynamic typing, and what counts as true.

≈ 12 min
03

Strings

Slicing, methods, f-strings, and why a string can never be changed.

≈ 13 min
04

Lists

Order, mutation, and the difference between another name and another list.

≈ 13 min
05

Tuples and sets

Unpacking, immutability, membership in constant time, and what may be hashed.

≈ 12 min
06

Dictionaries

The structure Python is built out of: lookups, defaults, grouping and counting.

≈ 13 min
07

Control flow

if / elif / else, while, for, and the loop-else clause almost nobody knows.

≈ 12 min
08

Comprehensions

The one-line loop that builds a list, a dict, a set — or nothing at all, lazily.

≈ 12 min
09

Functions

Arguments, defaults, *args and **kwargs — and the mutable default that bites everyone once.

≈ 14 min
10

Scope and closures

LEGB, global and nonlocal, and the loop that captures the wrong variable.

≈ 12 min
11

Errors and exceptions

try / except / else / finally, raising your own, and asking forgiveness rather than permission.

≈ 13 min
12

Modules and packages

import, __name__, the search path, and writing a module you can then import.

≈ 12 min
13

Files and paths

with open, text against bytes, encodings, pathlib, JSON and CSV.

≈ 12 min
14

Classes

State and behaviour together: __init__, attributes, methods, and what self really is.

≈ 14 min
15

Special methods

__repr__, __eq__, __hash__, __len__ — how an object joins the language itself.

≈ 13 min
16

Dataclasses

The boilerplate Python writes for you, and when a NamedTuple is the better answer.

≈ 12 min
17

Iterators and generators

The protocol behind every for loop, and yield — a million rows in constant memory.

≈ 14 min
18

Functional Python

sorted with a key, any and all, lambda, reduce, partial and a cache in one line.

≈ 12 min
19

Decorators

A function that wraps a function: timing, caching and logging without touching the code.

≈ 13 min
20

Context managers

with, __enter__ and __exit__, and contextlib — cleanup that happens even when it goes wrong.

≈ 12 min
21

Type hints

Annotations Python does not enforce, a checker that does, and Protocol for duck typing.

≈ 13 min
22

The standard library

datetime, re, collections, itertools, math and random — batteries, actually included.

≈ 13 min
23

Testing in Python

unittest and pytest-shaped tests, fixtures, parametrising, and what to assert.

≈ 13 min
24

Practice: a log analyser

One messy log file, real Python: parse it, group it, and answer four questions about it.

≈ 16 min