Abstract Base Classes and Interfaces
An abstract base class states what subclasses must implement, and refuses to let an incomplete one be created. It is how Python enforces a contract.
968 published notes across every category.
An abstract base class states what subclasses must implement, and refuses to let an incomplete one be created. It is how Python enforces a contract.
A class can inherit from several parents. The method resolution order decides which version wins, and C3 linearisation is the algorithm that computes...
Inheritance says "is a"; composition says "has a". Most of the time the honest answer is "has a", and the resulting design is easier to change.
An iterable can produce an iterator; an iterator produces one value at a time and remembers where it is. Every for loop in Python is built on those tw...
A generator function produces values one at a time and pauses between them, keeping all its local state. It is the easiest way to write an iterator an...
Lazy means computing a value only when it is asked for. Python uses it throughout, and using it deliberately is what makes a program handle data large...
A decorator takes a function, wraps it in another function, and gives the wrapper the original name. The @ symbol is shorthand for exactly that.
Registries, access control, deprecation, rate limiting and instrumentation - the decorator shapes that appear in real codebases, and how to test them.
A context manager guarantees that setup and cleanup both happen, whatever occurs in between. with is how you use one, and two methods are all it takes...
A descriptor is an object that controls what happens when an attribute is read, written or deleted. property, methods, classmethod and staticmethod ar...
A dataclass generates __init__, __repr__ and __eq__ from field declarations. It removes the boilerplate from every class whose main job is holding dat...
Everything in Python is an object with a type, an identity and a value. Names are labels bound to objects, and almost every surprising behaviour follo...