What is the Method Resolution Order (MRO), and how does `super()` use it?
Answer
The MRO is the linear order in which Python searches a class and its ancestors when looking up an attribute or method, computed by the C3 linearization algorithm so that a subclass always comes before its parents and a consistent order is preserved across all of a class's base classes. You can inspect it with `ClassName.__mro__`. `super()` does not simply mean "my direct parent class"; it returns a proxy that continues the lookup at the next class in the *current instance's* MRO after the calling class, which is what makes cooperative multiple inheritance work correctly.
Strong answer includes
- MRO is computed via C3 linearization, inspectable via __mro__
- subclass always precedes its parents in the order
- super() continues at the next class in the instance's MRO, not literally the parent
Practical example
In a diamond
class D(B, C):where both `B` and `C` inherit from `A` , `D.__mro__` is
(D, B, C, A, object), and calling
super().__init__()inside `B` moves on to `C` , not directly to `A` .