Skip to content

super()

super() returns a proxy object that lets a subclass call a method from the next class in its method resolution order (MRO) โ€” most commonly used to call a parentโ€™s __init__ so the subclass extends rather than completely overrides it.

Calling the parent class by name directly works for simple single inheritance, but hardcodes the parentโ€™s name and breaks down under multiple inheritance:

class Animal:
def __init__(self, name):
self.name = name
class Dog(Animal):
def __init__(self, name, breed):
Animal.__init__(self, name) # hardcodes the parent class name
self.breed = breed
class Animal:
def __init__(self, name):
self.name = name
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name) # no hardcoded parent name
self.breed = breed
d = Dog("Rex", "Labrador")
print(d.name, d.breed) # Rex Labrador
# super() also works for calling any method, not just __init__
class Shape:
def describe(self):
return "A shape"
class Circle(Shape):
def describe(self):
return super().describe() + ", specifically a circle"
print(Circle().describe()) # "A shape, specifically a circle"
  • No hardcoded parent name: super().__init__(name) keeps working even if the class hierarchy is later restructured (a new intermediate class inserted, for example).
  • Correct under multiple inheritance: super() follows the actual MRO, not just โ€œmy literal parentโ€ โ€” essential for cooperative multiple inheritance where each class in a chain should run exactly once (see the MRO page for the full mixin example).
  • Extends instead of replaces: calling super().__init__(...) then adding subclass-specific setup is the standard pattern for โ€œdo what the parent does, plus a bit more.โ€
  • In Python 3, super() with no arguments works inside an instance method (it infers the class and instance automatically); the old super(Dog, self) form still works but is rarely needed.
  • Forgetting to call super().__init__(...) in a subclassโ€™s __init__ means the parentโ€™s setup (e.g. self.name = name) never runs โ€” a common bug where an inherited attribute is simply missing.
  • super() resolves relative to the MRO of the actual instanceโ€™s class, not the class where the super() call is written โ€” this is what makes it correct even when called from deep in a multi-level hierarchy.
  1. Whatโ€™s the main advantage of super().__init__(name) over Animal.__init__(self, name)?

    AnswerIt doesn't hardcode the parent class's name, and it follows the MRO correctly under multiple inheritance โ€” `Animal.__init__(self, ...)` always calls exactly that class, which can be wrong or cause a class to run twice in a diamond hierarchy.
  2. What happens if a subclassโ€™s __init__ never calls super().__init__(...)?

    AnswerThe parent class's initialization never runs, so any attributes it would have set are simply missing on the instance.
  3. Does super() require explicit arguments in Python 3?

    AnswerNo โ€” `super()` with no arguments works inside instance methods; it automatically infers the class and instance from context.