Back to Course
Python Essentials: The Engineering Approach
Module 9 of 20
9. Advanced OOP
Dunder (Magic) Methods
You can teach your objects how to behave with Python operators.
__init__: Constructor__str__: String representation (for users)__repr__: Detailed representation (for developers)__eq__: Equality (==)__add__: Addition (+)
Composition over Inheritance
A classic engineering principle. Instead of building massive Inheritance trees, build small objects that hold other objects.
pythonclass Engine: def start(self): pass class Car: def __init__(self): self.engine = Engine() # Has-a Engine