Comprehensions & Generators
Transform collections concisely and stream values lazily.
Functions in Depth
Flexible signatures, functions as values, closures, and decorators.
*args, **kwargs & unpacking
Write functions that accept any number of arguments, and unpack collections into calls.
Lambdas & higher-order functions
Pass functions as values: sorted(key=...), map, and filter.
Scope, closures & decorators
Capture state in a closure and wrap behaviour with a decorator.
OOP Foundations
Model state and behaviour with classes, inheritance, composition, and dunders.
Classes, __init__, methods & self
Model state and behaviour together with a class.
Inheritance & composition
Extend a base class with inheritance, and build objects from other objects.
Dunder methods & properties
Give classes natural behaviour with __eq__/__repr__ and computed @property values.
Class methods, static methods & class attributes
Build alternative constructors with @classmethod, and know which state every instance shares.
Container & context protocols
Make your class work with len(), for, in, and with by implementing the dunders they call.
Data Modeling
Model data cleanly with dataclasses, enums, and type hints.
Errors, Files & Modules
Handle errors, parse JSON/CSV, and use the standard library.
try / except / finally & custom exceptions
Handle errors cleanly, raise your own, and define a custom exception.
Context managers, JSON & CSV
Read structured data with the with-statement, json, and csv.
Writing files without losing them
Truncate or append on purpose, write real lines, and rename into place so a crash cannot corrupt a file.
Text is bytes underneath
Encode and decode deliberately, and read the error that says these bytes were never UTF-8.
Modules, imports & the standard library
Organise code into modules and reach for Python's batteries-included stdlib.
Standard Library Toolkit
Reach for the batteries: regular expressions, specialized collections, and dates.
Pattern-matching text with re
Find, extract, and replace text patterns with regular expressions.
Counter, defaultdict & deque
Reach for specialized collections: count with Counter, group with defaultdict, queue with deque.
Dates, times & the naive-vs-aware trap
Parse and format timestamps, subtract them safely, and never mix naive with aware.
itertools: chain, islice, groupby & product
Name the loops you keep rewriting, keep them lazy, and never call groupby on unsorted rows.
Talking to Services
Make an HTTP call, then handle the status and the parse it hands back.