So far, we’ve used functions to organise code. Object-oriented programming (OOP) is a second way: we bundle related data and behaviour together into classes, then create objects from those classes.
Python is an OOP language at heart — every value you’ve ever used (a list, a string, a number) is an object. This section teaches you how to build your own.
What’s in this section
- Classes and objects — defining a class, creating instances
- Constructors and instance attributes —
__init__andself - Methods — functions that belong to a class
- Properties — controlled access to attributes
- Inheritance — building new classes on top of existing ones
- Data classes — classes with no boilerplate
We’ll keep the OOP simple here. The next section covers strict typing and Protocol, which is where modern Python’s type system really shines.