Python Super() function

Published February 17, 2022

Inheritance is one of the most essential OOP elements in Python. Inheritance is the process through which one class inherits one or more behaviours from another.
When one class inherits the behaviour of another, the inherited class becomes the subclass, while the original class becomes the parent class. The super() method is used to refer to the parent class in an inherited class. The super() function returns the superclass's temporary object, which gives access to all methods of its child class.

Take a look at the following example:

Example of a super() Function
 

class Student(object):
    def __init__(self, college):
        print('Name of the College:', college)
class Computer_science(Student):
    def __init__(self):
        # call superclass
        super().__init__('University of Hull')
        print('University of Hull offers Computer Science')
student = Computer_science()


Output

Name of the College: University of Hull
University of Hull offers Computer Science

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

222 Views