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

Veröffentlicht am: 14 Mai 2020
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video single inheritance in python | multilevel inheritance in python | super() in python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Tarun Sir 14 Mai 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 128 Mal angesehen und es wurde von 7 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!