Multiple Inheritance and MRO
Understand multiple inheritance and Python's MRO (C3 linearization).
Introduction
Python supports multiple inheritance. The Method Resolution Order (MRO) defines which method is called when names clash.
Multiple Inheritance Syntax
class C(A, B): inherits from both A and B. C gets all methods from both.
class A:
def hello(self): return 'A'
class B:
def world(self): return 'B'
class C(A, B): pass
c = C()
print(c.hello(), c.world())All lessons in this course
- Single Inheritance
- Method Overriding and super()
- Multiple Inheritance and MRO
- Polymorphism and Duck Typing