class A:
def __init__(self):
print('A')
class B():
def __init__(self):
print('B')
class C(A, B):
def __init__(self):
super(C, self).__init__()
print('C')
obj = C()
You can use the super method to call the method of the parent class, but how to use it in multiple inheritance?
The above code class C
will call the __init__
method of class A
, but if I want to call class A
and class B# at the same time ##How to write the '__init__' method? Or just call the
__init__ method of
class B?
Just call it explicitly, you can choose freely.
A.__init__(self)
A.__init__(self)
B.__init__(self)
B.__init__(self)
python-super