02 · OOP¶
Object-Oriented Programming — organize code around things instead of steps.
What you'll learn¶
- Classes and objects — a class is a blueprint (e.g., "Car"); an object is a thing built from that blueprint (your specific red Tesla).
- Attributes (data the object holds) and methods (things the object can do).
- Encapsulation — hiding internal state, exposing a controlled interface.
- Inheritance — a
Dogclass can inherit from anAnimalclass (gets all animal behavior plus its own). - Polymorphism — different objects responding to the same message in their own way.
- Special methods —
__init__,__str__,__repr__,__eq__.
Plain-language analogy¶
A class is like a cookie cutter; objects are the cookies. All cookies share the shape (the class), but each cookie can have its own icing (attributes) and its own bite marks (state changes over time).
When to use OOP vs just functions¶
- Data and behavior naturally bundle together → class.
- Stateless transformation → just a function.
- Many similar things with shared behavior → class hierarchy.