As discussed in python inheritance, inheritance is a process to inherit all the properties and methods from one class (base) to another class (child).
If required, you can implement two types of inheritances in python; those are
Suppose, if you create a class that inherits from more than one class, we will call it multiple inheritance in python.
To implement the multiple inheritance in python, you need to create a class that inherits from various classes, as shown below.
If you observe the above multiple inheritance example, the class Z is derived from both X and Y classes. Now, class Z will have access to all the resources of both X and Y classes.
Following is the example of multiple inheritance in python.
The above python multiple inheritance example will return the result as shown below.
In python, you also create a class that inherits all the features from the derived class, and we will call it a multilevel inheritance.
As discussed, inheritance is a process to inherit all the resources from base class to derived class, and multiple inheritance is a process to create a derived class that inherits resources from more than one base class. Similarly, if you create a class that inherits resources from a derived class, we will call it a multilevel inheritance.
To implement the multilevel inheritance in python, you need to create a class that inherits from the derived class, as shown below.
If you observe the above multilevel inheritance example, the class Y is derived from the base X class, and the Z class is created to inherit all the resources from the derived Y class. Now, the Z class will have access to all the resources of both X and Y classes.
Following is the example of multilevel inheritance in python.
The above python multilevel inheritance example will return the result as shown below.
This is how you can implement multiple and multilevel inheritance in python based on your requirements.