Python ProgrammingPython Programming

Example Call Parent Class Constructor from Child Class in Python

In this type of inheritance parent class attributes initialized using child class constructor.
class Family:
    # Parent class constructor
    def __init__(self, name):
        self.name = name
 
 
# Father class inherited from Family
class Father(Family):
    # Child class constructor
    def __init__(self, name, age):
        #  Parent class constructor called from child class
        Family.__init__(self, name)
        self.age = age
 
 
f = Father("Mark", 36)
print(f.name)
print(f.age)