The super() doesn’t know what class it’s being called in. we have to tell it which class’s parent’s function want to get. It is called super argument in Python.
Python super arguments example
class Vehicle: def __init__(self): print('Vehicle __init__() called') class Car(Vehicle): def __init__(self): super().__init__() car = Car()
Python multiple inheritance passing arguments to constructors using super
When dealing with multiple inheritances in general, your base classes should be designed for multiple inheritances.
class A(object): def __init__(self,a): self.a=a class B(A): def __init__(self,b,**kw): self.b=b super(B,self).__init__(**kw) class C(A): def __init__(self,c,**kw): self.c=c super(C,self).__init__(**kw) class D(B,C): def __init__(self,a,b,c,d): super(D,self).__init__(a=a,b=b,c=c) self.d=d
Do comment if you have any doubts and suggestions on this Python super topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.