November 12, 2014 · Public
Python supports multiple inheritance, allowing you to derive from more than one base class
at a time. This is different than chaining up from a single base class along a specific route of
inherited classes. In multiple inheritance, you combine separate base classes that are not involved
with each other to form a group of classes from which a derived class is ‘”built.”
Before we discuss multiple inheritance, a few warnings are in order. First, there are those in the
object-oriented community who consider multiple inheritance “bad.” It is true that it makes
the code more complicated and confusing, and can lead to some very strange errors. However,
there is nothing inherently wrong with a language feature, only how it is used and abused. If
you have a valid case where multiple inheritance will work best, you should use it. Now, with
that said, how do you implement inheriting from multiple classes in Python?
To inherit from more than one class, you simply list the classes individually on the class definition
line for your derived class. Let’s assume that you have three base classes: A, B, and C, and
want a fourth class D that inherits from all three. Let’s look at an example of this, and what is
required to make it all work.