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

Publicado el: 14 mayo 2020
en el canal de: 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


En esta página del sitio puede ver el video en línea single inheritance in python | multilevel inheritance in python | super() in python de Duración hora minuto segunda en buena calidad , que subió el usuario Tarun Sir 14 mayo 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 128 veces y le gustó 7 a los espectadores. Disfruta viendo!