Python call super constructor | Example code

Use __init()__ on super() inside the constructor of the subclass to invoke the constructor of the superclass in Python. In inheritance invoking the super constructor of a subclass invokes the constructor of its superclass.

Python calls the super constructor example

Simple example code use super() to invoke the super constructor

class SuperClass():

    def __init__(self):
        print("Super Constructor")


class SubClass(SuperClass):

    def __init__(self):
        super().__init__()
        print("Subclass Constructor")


print(SubClass())

Output:

Python call super constructor

Do comment if you have any doubts and suggestions on this Python constructor tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.