89DEVs

Python super() function

overview of super()

The super() function returns a temporary object, which allows reference to the parent class by the super keyword. It can be used to avoid the usage of the superclass.

use of super()

The super() function is used to give access to all methods and properties of a parent class. # use of super() function class Animal: def __init__(self, name): self.name = name def printname(self): print(self.name) class Dog(Animal): def __init__(self, name): super().__init__(name) rex = Dog('rex') rex.printname() The class Dog inherits the methods and properties of the class Animal. When the printname() method is called, the name of the dog is printed. The method has been inherited from the class Animal because of the use of the super() function. rex

syntax of super()

The syntax of the super() function is: super()

arguments of super()

The super() function doesn't accept any arguments.

return value of super()

The super() function returns an object that represents the parent class and is used to refer to the parent class by using the keyword super.

                
        

Summary


Click to jump to section