Skip to content

Python call super constructor | Example code

  • by

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 or suggestions on this Python constructor tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading