Objects and classes

Designing your own types, reusing them through inheritance, and making them work with Python's built-in operations.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Classes and objects Intermediate

    Design your own types with attributes and methods, and watch objects live in memory.

  2. 2

    Inheritance Intermediate

    Build new classes on top of old ones, override methods, and call the parent with super().

  3. 3

    Special methods Intermediate

    Make your objects print nicely, compare with ==, add with +, and work with len().

Module practice

Module quiz

1. In __init__, what is the difference between self.x = 1 and x = 1?
2. How do you make len(obj) work for your class?
3. A child class defines a method with the same name as its parent's. What is this called?
4. Which relationship suits inheritance best?
5. Why should __add__ return a new object rather than change self?

‹ Reliable codeRecursion and data structures ›