There are multiple types of inheritance:
- Simple Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
MRO determines the Order in which a given method or attribute passed is searched.
Object is first searched in class Object then the parent class:
But what about multiple inheritance? Here, first the method is searched in the child class then the class Y and X.
Old version of python used to use Depth First Search DFS algorithm. But from python 3.0 it uses C3 linearization
Some features of C3 linearization algorithm
’s are:
Following is an example of MRO attribute:
Here the num=9
from the class B will be inherited.
Help function provides the MRO on top and is much more descriptive:
This outputs:
Why A comes after D?