Cooperative Multiple Inheritance — ELI5

Imagine a kid who learns cooking from Mom, gardening from Dad, and painting from Grandma. Each family member teaches their own thing, and nobody steps on anyone’s toes. When the kid needs to cook, they use Mom’s lessons. For gardening, Dad’s. Everyone cooperates.

That’s cooperative multiple inheritance in Python. A class can have multiple parent classes, and each parent agrees to do its part and then pass the baton to the next one using super().

Why “Cooperative”?

The word “cooperative” is important. Each parent class promises to call super() so the next parent in line gets a chance to do its job too. If even one parent breaks the chain and doesn’t call super(), the system falls apart — like a relay race where one runner keeps the baton.

A Simple Picture

Think of a relay race with three runners:

  1. Runner A does their part, passes the baton.
  2. Runner B does their part, passes the baton.
  3. Runner C finishes.

If Runner B decides to stop and sit down, Runner C never runs. In Python, every parent class needs to pass the baton by calling super().

Why Not Just One Parent?

Sometimes a class genuinely needs abilities from two different sources. A FlyingCar needs both Car stuff and Aircraft stuff. Instead of copying code, it inherits from both and lets them cooperate.

One thing to remember: Cooperative multiple inheritance works because every parent class agrees to call super() and let the next parent have a turn.

pythonadvancedoop

See Also