Computer >> Computer tutorials >  >> Programming >> Python

How do I make a subclass from a super class in Python?


We use "super", a Python Built-in function, which is  a slightly better method of calling the parent class for initialization. Following code illustrates the use of 'super'.

Example

# Initializing using just Parent
class MySubClass(MySuperClass):
    def __init__(self):
        MySuperClass.__init__(self)
# Initializing using Parent with super().
class MySubClassBetter(MySuperClass):
    def __init__(self):
        super(MySubClassBetter, self).__init__()