2.7 The object Class and Python Special Methods

Now that we understand inheritance, we can gain a deeper understanding of some of Python’s fundamental special methods.

The object superclass

In our very first lecture, we described every piece of data as an object, and have continued to use this term throughout this course. It turns out that “object” is not merely a theoretical concept, but made explicit in the Python language. In Python, we have a class called object, which is an ancestor of every other class, both built-in classes like int or our user-defined classes like Employee. By “ancestor” we mean either a parent class, or a parent of a parent class, etc.

Inheriting special methods

This object class gives default implementations for many special methods we have seen before, including:

Keep in mind that even though these methods are called “special”, overriding them in your classes works in the exact same way as other methods: simply define a method with the specific name of that special method.