Classes, inheritance, magic methods, dataclasses, and design patterns
Build your first class: __init__, self, methods, attributes, and __str__. The foundation of object-oriented Python.
Subclasses, method overriding, super(), and polymorphism — reuse and extend code without rewriting it.
@classmethod builds alternative constructors; @staticmethod groups utility functions. Know when to reach for each.
Turn method calls into attribute access with @property. Add validation, compute values on the fly, and keep your API clean.
The __dunder__ methods that make Python objects behave like built-in types — __str__, __len__, __eq__, __getitem__, and more.
Make your classes work with +, -, ==, and other operators using __add__, __sub__, __eq__, and their reflected variants.
Enforce interfaces in Python with Abstract Base Classes. Define contracts that subclasses must follow.
How Python resolves the diamond problem with MRO, how super() works in complex hierarchies, and practical mixin patterns.
Cut the boilerplate. @dataclass generates __init__, __repr__, and __eq__ for you. Less typing, more readable data classes.
Three ways to structure data — NamedTuple, TypedDict, and dataclass. When each one fits and when it doesn't.
Reduce memory usage by ~40% with __slots__. How it works, when to use it, and what you give up.
Validation with __post_init__, immutability with frozen=True, complex defaults with field(), and dataclass inheritance.
Why 'has-a' often beats 'is-a'. Refactor fragile inheritance into clean composition with dependency injection.