Skip to content

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.

  1. Classes and objects: Define a class, create objects with __init__, and call methods that use self. ~20 min
  2. Encapsulation and properties: Keep rules for changing data next to the data, and use @property with a validating setter. ~20 min
  3. Inheritance and super: Build a subclass from a parent class, override methods, and call the parent's version with super(). ~20 min
  4. Polymorphism and protocols: Call one method on objects of different classes, and require methods with abstract base classes and protocols. ~20 min
  5. Dunder methods: Make operators, len, in, and sorted work with your own classes. ~20 min