In this article we are going to talk about Super() Function in Python,
Python Super() Function is used for accessing to the methods and properties
of the parent class or base class, and super function returns a proxy object.
Now let’s create a practical example on Python Super() function.
1 2 3 4 5 6 7 8 9 10 11 |
class Person: def __init__(self): print("Geekscoders - Base Class Person") class Student(Person): def __init__(self): print("Geekscoders - Derived Class Student ") st = Student() |
in the above code we have two classes, the first class is Person class and it is our
parent class, we have our initializer method in this class, also in the initializer we are
just printing some texts in the console. the second class is Student class and it is a child
class of the Person class, and in here also we are going to print something in the console.
now if you run this code you will see that it is not calling the base class initializer method,
but it is calling the derived class initializer method.
This is the result and as we can see it is calling the derived class initializer method.

Now what if we want to call our base class initializer method, for that we
are going to use the super function in Python, let’s bring changes to our code
and add the super function.
1 2 3 4 5 6 7 8 9 10 11 12 |
class Person: def __init__(self): print("Geekscoders - Base Class Person") class Student(Person): def __init__(self): super().__init__() print("Geekscoders - Child Class Student") st = Student() |
Run the code and you will see that it is calling the base class initializer method.

Let’s create another example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Person: def __init__(self, name, age): self.name = name self.age = age class Student(Person): def __init__(self, name, age, email): super().__init__(name, age) self.email = email st = Student("Geekscoders", 20, "geekscoders@gmail.com") print(st.name) print(st.age) print(st.email) |
In this code, Person is a super (parent) class, while Student is a derived (child) class.
The usage of the super function allows the child class to access the parent class’s init()
property. In other words, super() allows you to build classes that easily extend the
functionality of previously built classes without implementing their functionality again.
Run the code and this is the result.
