In this example we will show how to make the child class inherit all the methods and properties from its parent using the super() function in Python.
Source Code
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def print_person_info(self):
print('name:', self.name, 'age:', self.age)
class Student(Person):
def __init__(self, name, age):
super().__init__(name, age)
s = Student('John', 15) # create an object
s.print_person_info() # execute the print_person_info method
Output:
name: John age: 15