Part 7: Objects¶
This part covers how to group data and the functions that work on it into classes. You will create objects, protect their data with properties, reuse code through inheritance, write code that works across classes, and make your own classes work with operators. Work through the lessons in order, because each one builds on the ideas of the lessons before it.
- Classes and objects: Define a class, create objects with
__init__, and call methods that useself. ~20 min - Encapsulation and properties: Keep rules for changing data next to the data, and use
@propertywith a validating setter. ~20 min - Inheritance and super: Build a subclass from a parent class, override methods, and call the parent's version with
super(). ~20 min - Polymorphism and protocols: Call one method on objects of different classes, and require methods with abstract base classes and protocols. ~20 min
- Dunder methods: Make operators,
len,in, andsortedwork with your own classes. ~20 min