🐍 Python Intermediate

What is Python's inheritance and MRO?

Why Interviewers Ask This

This tests whether you can apply Python knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

Python supports multiple inheritance: class C(A, B) inherits from both A and B. The Method Resolution Order (MRO) determines the order in which base classes are searched when looking up a method. Python uses the C3 linearization algorithm. View the MRO: C.__mro__ or C.mro(). Generally, the MRO is: the class itself, then left-to-right through base classes, with each class appearing after all classes that inherit from it. super() follows the MRO — even in multiple inheritance, it does not simply call the parent class's method; it calls the next class in the MRO. This enables cooperative multiple inheritance where all classes in the chain properly call super(). The diamond problem (class D inheriting from B and C which both inherit from A) is handled cleanly by MRO — A is only visited once.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.