Python - Class Superclass Constructors


If subclass constructors need to guarantee that superclass construction, they generally must call the superclass's __init__ method explicitly through the class:

class Super: 
   def __init__(self, x): 
       ...default code... 

class Sub(Super): 
   def __init__(self, x, y): 
       Super.__init__(self, x)             # Run superclass __init__ 
       ...custom code...                   # Do my init actions 

I = Sub(1, 2) 
print( I )

Here, we used the Super.__init__ to call constructor from base class.

Related Topic