Learn: Type hints¶
Four notebooks, in order. Each is self-contained but they build on each other — if you work through them in sequence you'll cover the whole topic once.
Notebooks in this section¶
- Why type hints? — what they are, what they aren't, and what problem they solve. How type-checkers use them.
- Basic annotations — annotating variables, function parameters, and return types. The built-in types (
int,str,bool, etc.) and how they compose. - Generics and collections — typing containers:
list[int],dict[str, int],tuple[int, str], custom generics viaTypeVar. - Optional, Union, and friends —
X | None,X | Y,Literal,Callable,TypedDict,Anyandobject. The expressive forms you'll reach for as your typing gets more ambitious.
After these, the Recipes show task-focused applications and the Reference has lookup tables for the typing module.