Tutorial 7 : OOPs in Python — super() function
Missed previous tutorial ? : Click hare
We have already discussed about inheritance. In inheritance, super() function is used to access parent class methods directly inside child class without mentioning parent class name explicitly.
super() in single inheritance : Example 1
Using super() function in child/derived class :
super().parent_class_method_name(parent_class_method_attributes)
Let’s see it using examples:
super() in single inheritance : Example 1


Here we have not created any object of parent class, still we can assign the values to the attributes of parent class using super() function.
Example 2 :


So we can directly assign the values to the attributes inside child class too without having to create parent class object.
Example 3 :


Example 4 :


super() in multiple inheritance : Example 5


Example 6 :
When two base classes have same method name with different functionalities then first base class is given preference. Let’s see it using example given below :



Example 7 :
When two base classes have different methods then we do not have to mention the base class from which method is going to be inherited when we use super() function. Let’s see it using example given below :


I hope now you have clear understanding of using super() function in single and multiple inheritance.
Congratulations !!
You have completed seventh tutorial. Take a deep breathe and move to the next tutorial.