Skip to content
UPEEC

Multiple Inheritance and the MRO

A class can inherit from several bases; Python resolves methods with the C3 Method Resolution Order.

Intermediate
Comments 0
class A: 
    def hi(self): return "A"
class B(A): 
    def hi(self): return "B" + super().hi()
class C(A): 
    def hi(self): return "C" + super().hi()
class D(B, C): pass

D().hi()        # "BCA"
D.__mro__       # D, B, C, A, object

Mixins — small classes that add one behaviour — are the common healthy use.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.