Hands-On Enterprise Application Development with Python
上QQ阅读APP看书,第一时间看更新

Multiple inheritance in Python

Let's take a look at an abstract example of how we can implement multiple inheritance in Python, as can be seen in the code snippet that follows:

class A:
def __init__(self):
print("Class A")

class B:
def __init__(self):
print("Class B")

class C(A,B):
def __init__(self):
print("Class C")

The example shows how we can get multiple inheritance to work in Python. One interesting thing here is to understand how the method resolution order works in Python when we use multiple inheritance. So, let's take a look.