Python Multiple Inheritance and MRO
The other half of PCAP objective 4.5. A class may have several parents, and the method resolution order decides which one wins. The order is left to right and depth-limited in a specific way, super() follows it rather than jumping to a parent, and some inheritance orders are impossible and rejected at class-creation time. Every claim on this page is printed from __mro__ rather than reasoned about.
Object-Oriented Python Guide 19 of 25 Advanced
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 18 min
Python 3 uses C3 linearisation for the MRO, as Python 2.3 onwards did for new-style classes. Old-style classes had a simpler depth-first order and no longer exist.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the multiple-inheritance half, the hardest material on PCAP. This matters because the order you list the bases decides which method wins - and super follows the resolution order rather than the parent you expect.
- listing two parents, and seeing the order decide
- walking the diamond, both when one parent defines the method and when only the other does
- finding that
superfollows the MRO rather than the parent - meeting an inheritance order Python refuses outright
- seeing every class end at
object, and writing a mixin
Before you start
-
Two parents, and the order decides
-
The diamond
-
The diamond where only C defines the method
-
super follows the MRO, not the parent
-
An inheritance order Python refuses
-
Every class ends at object
-
A mixin, which is what multiple inheritance is really for
-
What the exam does with this objective