Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries

The Python super() function is used to initialize base class object in derived class (in single inheritance), hence helps derived class to inherit all the methods and properties of base class without explicitly mentioning base class name.




No parameter is required.


In the below example, a base class called polygon and derived class called square are created. According to the inheritance property, the __init__() function of base class polygon is overridden by __init__() function of derived class square. Hence, object of derived class square requires only one parameter to initialize the object. To access all the methods and properties of base class polygon, super() function is used in derived class square.

class polygon:
  def __init__(self, length, breadth):
    self.length = length
    self.breadth = breadth
  def area(self):
    return self.length * self.breadth
class square(polygon):
   def __init__(self, side):
      super().__init__(side, side)
MySquare = square(3)

The output of the above code will be:


❮ Python Built-in Functions