Inheritance is the advance feature of python in object oriented programming, it allows us to define a class that inherits all the methods and properties from another class.
Inheritance in python is a mechanism in which one object acquires all the properties and behaviors of parent object.
The idea behind inheritance in python is that the user can create new classes that are built upon already existing classes.
When inheriting from an existing class, the users can reuse methods and fields of parent class, and can add new methods and fields also.
Inheritance is also known as parent-child relationship.
class parent: statements class child(parent): statements
This is Parent Class This is Child Class
In Python, there are four types of Inheritance:
A class extends another class (only one class).
class A: # variable of class A # functions of class A class B(A): # variable of class A # functions of class A
This is Parent Class This is Chile Class
In Python, One class extending (Or inherits) more than one base class is called Multiple Inheritance.
This is Parent Class This is Parent Class2 Inherited both Parent and Parent2 class
One class can inherited from a derived class, thereby making this derived class the base classs for the new class is called Multi-level Inheritance.
One Class is inherited by many sub classes is called Hierarchical Inheritance in python.
This is Parent Class Child Class inheriting Parent class Child2 Class inheriting Parent class