Feb-14-2020, 09:16 PM
It's not mandatory. But if you want the A.__init__ method to handle its own initialization and B.__init__() just something bit more, you wave to call it.
And the proper way is to call super():
And the proper way is to call super():
class B(A): def __init__(self): super.__init__() # instead of A.__init(self)When you use multiple inheritances don't calling super() could cause some issues.
In [1]: class A: ...: def __init__(self): ...: print('A') ...: In [2]: class B(A): ...: def __init__(self): ...: A.__init__(self) ...: print('B') ...: In [3]: class C(A): ...: def __init__(self): ...: A.__init__(self) ...: print('C') ...: In [4]: class D(B, C): ...: def __init__(self): ...: B.__init__(self) ...: C.__init__(self) ...: print('D') ...: In [5]: obj = D() A B A CAs you can see A is called twise.