Python
Object-Oriented Programming
Inheritance
Method Overriding
Parent Class

How do I call a parent class's method from a child class in Python?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Python, the standard way for a child class to call a parent class method is super(). It is concise, respects Python's method resolution order, and is the right default in almost all inheritance code. Directly naming the parent class also works in some cases, but it is less flexible and becomes risky in multiple-inheritance hierarchies.

Basic Example with super()

Start with a parent method and override it in the child.

python
1class Animal:
2    def speak(self):
3        print("Animal sound")
4
5
6class Dog(Animal):
7    def speak(self):
8        super().speak()
9        print("Woof")
10
11
12d = Dog()
13d.speak()

Output:

text
Animal sound
Woof

super().speak() calls the parent implementation before the child adds its own behavior.

Calling the Parent Constructor

The same pattern is common in __init__.

python
1class Animal:
2    def __init__(self, name):
3        self.name = name
4
5
6class Dog(Animal):
7    def __init__(self, name, breed):
8        super().__init__(name)
9        self.breed = breed
10
11
12d = Dog("Milo", "Beagle")
13print(d.name, d.breed)

If the parent constructor initializes important state, skipping super().__init__() often leaves the object partially broken.

Direct Parent-Class Calls

You can also call the parent explicitly by name.

python
1class Animal:
2    def speak(self):
3        print("Animal sound")
4
5
6class Dog(Animal):
7    def speak(self):
8        Animal.speak(self)
9        print("Woof")

This works in simple inheritance, but it hardcodes the parent class into the child. That makes refactoring harder and breaks the cooperative behavior expected in multiple inheritance.

Why super() Is Better

super() is not just syntactic sugar. It participates in Python's method resolution order, or MRO, which defines how Python walks a class hierarchy.

That matters most when several base classes are involved.

python
1class A:
2    def process(self):
3        print("A")
4
5
6class B(A):
7    def process(self):
8        print("B start")
9        super().process()
10        print("B end")
11
12
13class C(A):
14    def process(self):
15        print("C start")
16        super().process()
17        print("C end")
18
19
20class D(B, C):
21    def process(self):
22        print("D start")
23        super().process()
24        print("D end")
25
26
27D().process()
28print(D.__mro__)

super() lets each class cooperate with the MRO instead of jumping directly to one named parent.

When to Override and Extend Versus Replace

Not every override should call the parent method. It depends on semantics.

Call the parent when:

  • the parent does essential setup
  • you are extending behavior
  • the class contract expects cooperative inheritance

Do not call the parent when:

  • the child intentionally replaces the behavior
  • the parent implementation is irrelevant or harmful for the child case

The decision is about class design, not only syntax.

Class Methods and Static Methods

The same idea applies to class methods, though the call looks slightly different.

python
1class Parent:
2    @classmethod
3    def describe(cls):
4        print(f"Parent logic on {cls.__name__}")
5
6
7class Child(Parent):
8    @classmethod
9    def describe(cls):
10        super().describe()
11        print("Child logic")
12
13
14Child.describe()

For static methods, there is no implicit instance or class context, so direct naming is often simpler if you truly need to call the parent version.

A Practical Rule

For normal inheritance in modern Python:

  • use super() in instance methods
  • use super() in constructors
  • use super() in class methods when cooperating with a hierarchy

Only call the parent class by name when you have a specific reason and understand the tradeoff.

Common Pitfalls

One common mistake is forgetting to call super().__init__() when the parent constructor sets up required attributes.

Another mistake is using direct parent-class calls in a codebase that later grows into multiple inheritance. That can bypass the intended MRO completely.

Developers also assume super() means "call my immediate parent." In Python, it really means "continue method lookup according to the MRO."

Finally, some child overrides call the parent unconditionally even when the child is supposed to replace, not extend, the behavior.

Summary

  • The standard way to call a parent method in Python is super().
  • 'super() is the right default because it respects the method resolution order.'
  • Direct parent-class calls work in simple cases but are less flexible.
  • Constructors are a common place where super() is essential.
  • Choose whether to extend or replace parent behavior intentionally, not mechanically.

Course illustration
Course illustration

All Rights Reserved.