How to Call __init__ for Multiple Inheritance In Python

Peter Xie
Feb 4, 2023

How to initiate multiple inheritance is not addressed with simple examples in Python Tutorial. You may be confused as I am. I personally won’t recommend using multiple inheritance as it is not intuitive, but here is how if you want to.

TL;DR:

class A:
def __init__(self, a):
self.a = a

class B:
def __init__(self, b):
self.b = b

class C(A, B):
def __init__(self, c):
A.__init__(self, c)
B.__init__(self, c * 2)
self.c = c * 3

c = C(1)
print(c.a, c.b, c.c)

# OUT
1 2 3

--

--