Programming6 min read10 interview questionsNew · November

Python super() and multiple inheritance

How Python decides which parent class runs next, and how to use super() safely.

In one sentencesuper() gives you the next class in Python's method resolution order, so a child can reuse its parents' code without naming them.

Think of it like thisThink of a chain of command: each manager passes the request up to the next in a fixed order, and super() means "pass it on".

The big picture

Tap any step to see where to use it, how to use it and an example result.

Single inheritance

A child class gets the methods of its parent. When the child defines __init__, it should usually call super().__init__() so the parent sets up its own attributes first. Without that call, the parent's setup is skipped.

Multiple inheritance and the MRO

A class can have several parents, such as class C(A, B). Python lists the classes in a fixed order called the method resolution order, found with C.__mro__. It follows the C3 rule: children before parents, and the order you wrote is kept. super() follows this list, not just the direct parent.

The diamond

If B and C both inherit from A, and D inherits from B and C, the order is D, B, C, A. A appears once, and each super().__init__() call moves one step along that list, so A's setup runs only once.

Writing cooperative classes

For multiple inheritance to work, every class in the chain should call super().__init__() and pass on extra arguments, commonly by accepting **kwargs. Keep hierarchies small, and prefer composition (holding another object) when inheritance becomes confusing.

Common mistakes

  • Forgetting to call super().__init__() in a child.
  • Calling a parent by name, such as A.__init__(self), in a diamond, which can run A twice.
  • Assuming super() means "my direct parent" only.
  • Building deep inheritance trees when simple composition would do.

Quick recap

  • super() returns the next class in the MRO.
  • Check the order with ClassName.__mro__.
  • Every class in the chain should call super().__init__().
  • Prefer composition when inheritance gets complex.

Try it yourself

Create classes A, B, C(A) and D(B, C), each printing its name in __init__ and calling super().__init__(). Print D.__mro__ and compare it with the order of the printed names.

Top 10 interview questions

Ordered from basic to advanced. Try answering out loud first, then open the answer.

  1. What does super() do in Python?Basic

    It gives access to the next class in the method resolution order, so you can call a parent's version of a method such as __init__.

  2. Why call super().__init__() in a child class?Basic

    So the parent class can initialise its own attributes. If you skip it, those attributes may be missing and later code can fail.

  3. What is inheritance?Basic

    A way for one class (the child) to reuse and extend the attributes and methods of another (the parent).

  4. What is the difference between super().__init__() and ParentClass.__init__(self)?Basic

    super() follows the method resolution order and works correctly with multiple inheritance. Naming the parent directly hardcodes it and can skip or repeat classes.

  5. What is the method resolution order?Intermediate

    The order in which Python searches classes for an attribute or method. View it with ClassName.__mro__ or ClassName.mro().

  6. How does Python calculate the MRO?Intermediate

    With the C3 linearisation algorithm. It keeps each class before its parents, preserves the left to right order of the base classes, and rejects inconsistent hierarchies with a TypeError.

  7. What is the diamond problem and how does Python handle it?Intermediate

    When a class inherits from two classes that share a parent, it is unclear which parent code runs and how many times. The MRO lists the shared parent once, so cooperative super() calls run it only once.

  8. Do you need arguments in super() in Python 3?Intermediate

    No. Inside a method, super() with no arguments works. The older form super(ClassName, self) is only needed in unusual cases.

  9. What is cooperative multiple inheritance?Advanced

    A design where every class calls super() and passes unknown arguments along, usually through **kwargs, so each class in the MRO can contribute. It only works if all classes follow the pattern.

  10. When should you use composition or mixins instead of deep inheritance?Advanced

    Prefer composition when the relationship is "has a" rather than "is a", or when the hierarchy is hard to reason about. Mixins are small classes that add one behaviour and work well when kept simple and without their own state.

Back to Learn Hub

Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.