Multiple Inheritance and MRO
Understand multiple inheritance and Python's MRO (C3 linearization).
Multiple Inheritance and MRO is a free Python Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Introduction
Multiple Inheritance Syntax
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())Method Resolution Order (MRO)
class A:
def greet(self): return 'A'
class B:
def greet(self): return 'B'
class C(A, B): pass
print(C().greet()) # A wins
print(C.__mro__)C3 Linearization
class A: pass
class B(A): pass
class C(A): pass
class D(B, C): pass
print([c.__name__ for c in D.__mro__])Diamond Inheritance
class A:
def __init__(self): print('A')
class B(A):
def __init__(self): super().__init__(); print('B')
class C(A):
def __init__(self): super().__init__(); print('C')
class D(B, C):
def __init__(self): super().__init__(); print('D')
D()Mixins
class JSONMixin:
def to_json(self):
import json
return json.dumps(vars(self))
class User(JSONMixin):
def __init__(self, name, age): self.name,self.age=name,age
print(User('Alice', 30).to_json())Mixin Design Rules
class LoggingMixin:
def log(self, msg): print(f'[{self.__class__.__name__}] {msg}')
class Service(LoggingMixin):
def run(self): self.log('running')
Service().run()super() in Multiple Inheritance
class Base:
def action(self): return 'Base'
class A(Base):
def action(self): return 'A->' + super().action()
class B(Base):
def action(self): return 'B->' + super().action()
class C(A, B):
def action(self): return 'C->' + super().action()
print(C().action())type() for Dynamic Class Creation
def hello(self): return 'hello'
MyClass = type('MyClass', (object,), {'hello': hello})
print(MyClass().hello())Checking the MRO
class A: pass
class B(A): pass
class C(B): pass
import inspect
print([c.__name__ for c in inspect.getmro(C)])When to Avoid Multiple Inheritance
# Prefer:
class User:
def __init__(self, name, logger):
self.name = name
self.logger = logger # composition
print('composition preferred')Quick Check
Recap
Keep Going
Frequently asked questions
Is the “Multiple Inheritance and MRO” lesson free?
Yes — the full text of “Multiple Inheritance and MRO” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Multiple Inheritance and MRO”?
Understand multiple inheritance and Python's MRO (C3 linearization). You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Multiple Inheritance and MRO” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Single Inheritance
- Method Overriding and super()
- Multiple Inheritance and MRO
- Polymorphism and Duck Typing