Python · Section 2
Object-Oriented Python
How to define a class, build objects from it, and give them behaviour — then the three ways one object can relate to another, and when to reach for inheritance versus composition.
This section
- OOP fundamentalsHow to define a class, build objects from it, and give them behaviour — then the three ways one object can relate to another, and when to reach for inheritance versus composition.5 core10 standard15 concepts
- Abstract classes and interfacesHow to require a method with abc — versus how Python already lets any matching shape stand in without any inheritance at all, and how typing.Protocol makes that shape a type checker can verify.2 core4 standard6 concepts
- PropertiesHow @property turns a method into an attribute-style read, how a setter and deleter make it writable and deletable, and why deriving a value on every read means it can never go stale.2 core2 standard4 concepts
- Dunder methodsThe methods Python calls for you behind the scenes — construction, string display, comparison, hashing, truthiness, containers, iteration, indexing, the with statement, and calling an instance like a function.3 core9 standard12 concepts
- Advanced OOPHow Python resolves attribute lookups across multiple bases, reusable behaviour via mixins, the descriptor and attribute-access protocols underneath @property itself, and the two lowest-level customization hooks — __slots__ and metaclasses.1 core3 standard2 reference6 concepts

