Basic inheritance
Technically, every class we create uses inheritance. All Python classes are subclasses of the special built-in class named object
. This class provides a little bit of metadata and a few built-in behaviors so Python can treat all objects consistently.
If we don't explicitly inherit from a different class, our classes will automatically inherit from object
. However, we can redundantly state that our class derives from object
using the following syntax:
class MySubClass(object):
pass
This is inheritance! This example is, technically, no different from our very first example in Chapter 2, Objects in Python. In Python 3, all classes automatically inherit from object
if we don't explicitly provide a different superclass. The superclasses, or parent classes, in the relationship are the classes that are being inherited from, object
in this example. A subclass – MySubClass
, in this example &...