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

PythonServer Side ProgrammingProgramming

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__()
raja
Published on 16-Jan-2018 17:58:53
Advertisements