single inheritance in python | multilevel inheritance in python | super() in python

Published: 14 May 2020
on channel: Tarun Sir
128
7

In this video you will learn types of inheritance in python. I will teach you how to implement single inheritance and multilevel inheritance.

Types of Inheritance in python
In python we can have following 5 types of inheritance:
• Single inheritance
• Multilevel Inheritance
• Hierarchical Inheritance
• Multiple Inheritance
• Hybrid Inheritance

In this video we will learn about single inheritance and multilevel inheritance in python.
Single inheritance
When a single child class is inherited from a single parent class then it is called as single inheritance. Consider the following example:

class Person:
def __init__(self,name,age):
self.name=name
self.age=age

def printPersonalDetails(self):
print(f"Name\t:\t{self.name}\nAge\t:\t{self.age}")

class Student(Person):
def __init__(self,name,age,roll,college):
Person.__init__(self,name,age)
self.roll=roll
self.college=college
def printStudentDetails(self):
print(f"College\t:\t{self.college}\nRoll\t:\t{self.roll}")

s=Student("Tarun Verma",32,1234,"NIELIT")
s.printPersonalDetails()
s.printStudentDetails()


Multilevel Inheritance
When a child class become a parent of another class, then it is called as multilevel inheritance. It means the inheritance diagram have level of classes. Consider the following example:

class Person:
def __init__(self,name,age):
self.name=name
self.age=age

def printPersonalDetails(self):
print(f"Name\t:\t{self.name}\nAge\t:\t{self.age}")

class Student(Person):
def __init__(self,name,age,roll,college):
Person.__init__(self,name,age)
self.roll=roll
self.college=college
def printStudentDetails(self):
print(f"College\t:\t{self.college}\nRoll\t:\t{self.roll}")

Define Employee class, and inherit it from Student
class Employee(Student):
def __init__(self,name,age,roll,college,salary,designation):
super().__init__(name,age,roll,college)
self.salary=salary
self.designation=designation

def printEmployeeDetails(self):
print(f"Designation\t:\t{self.designation}\nSalary\t:\t{self.salary}")

e=Employee("Abhishek Bishnoi",24,12345,"GECB",28500,"Associate Developer")
e.printPersonalDetails()
e.printStudentDetails()
e.printEmployeeDetails()

#python_by_tarun_sir #tarun_sir #python #tarun_sir_python #python_video_65 #single_inheritance_in_python #python_tutorial #multilevel_inheritance_in_python #super()_in_python


On this page of the site you can watch the video online single inheritance in python | multilevel inheritance in python | super() in python with a duration of hours minute second in good quality, which was uploaded by the user Tarun Sir 14 May 2020, share the link with friends and acquaintances, this video has already been watched 128 times on youtube and it was liked by 7 viewers. Enjoy your viewing!