0Pricing
Python Academy · Lesson

Method Overriding and super()

Override parent methods and call them with super().

Method Overriding and super() is a free Python Academy lesson on CoddyKit — lesson 2 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

Method overriding lets child classes customize inherited behavior. super() lets you call the original implementation.

Overriding Basics

Define the same method name in the child class to replace the parent's version for all instances of the child.
class Greeter:
    def greet(self): return 'Hello'
class FormalGreeter(Greeter):
    def greet(self): return 'Good day'
print(FormalGreeter().greet())

super() in Overrides

super().greet() inside the child calls the parent's version. Useful for extending, not completely replacing, behavior.
class Logger:
    def log(self, msg): print(f'[LOG] {msg}')
class TimedLogger(Logger):
    def log(self, msg):
        import time
        super().log(f'{time.time():.0f}: {msg}')
TimedLogger().log('test')

super() in __init__

Always call super().__init__() in a child's __init__ to ensure the parent's initialization runs.
class Animal:
    def __init__(self, name): self.name = name
class Cat(Animal):
    def __init__(self, name, indoor):
        super().__init__(name)
        self.indoor = indoor
cat = Cat('Whiskers', True)
print(cat.name, cat.indoor)

super() with Arguments

super(ChildClass, self) is the explicit form (Python 2 style). Python 3 allows super() with no args in most cases.
class A:
    def greet(self): return 'A'
class B(A):
    def greet(self): return super().greet() + 'B'
class C(B):
    def greet(self): return super().greet() + 'C'
print(C().greet())

Cooperative Inheritance

In multiple inheritance, super() follows the MRO. Every class calling super() ensures all classes in the chain are initialized.
class A:
    def __init__(self): print('A init')
class B(A):
    def __init__(self): super().__init__(); print('B init')
class C(A):
    def __init__(self): super().__init__(); print('C init')
class D(B, C):
    def __init__(self): super().__init__(); print('D init')
D()

Overriding __str__

Override __str__ in the child to customize how instances are printed.
class Animal:
    def __init__(self, name): self.name = name
    def __str__(self): return f'Animal: {self.name}'
class Dog(Animal):
    def __str__(self): return f'Dog: {self.name}'
print(Dog('Rex'))

Template Method Pattern

Parent defines the algorithm skeleton; child fills in the steps by overriding specific methods.
class DataProcessor:
    def process(self):
        data = self.load()
        return self.transform(data)
    def load(self): return [1,2,3]
    def transform(self, d): return d
class Doubler(DataProcessor):
    def transform(self, d): return [x*2 for x in d]
print(Doubler().process())

Calling Sibling Method

With super() and proper MRO, you can call a sibling class's method in multiple inheritance — this is cooperative super().
class A:
    def hello(self): print('A')
class B(A):
    def hello(self): super().hello(); print('B')
class C(A):
    def hello(self): super().hello(); print('C')
class D(B,C):
    def hello(self): super().hello(); print('D')
D().hello()

__init_subclass__

__init_subclass__ is called whenever the class is subclassed. Useful for plugin registration patterns.
class Plugin:
    registry = []
    def __init_subclass__(cls, **kw):
        super().__init_subclass__(**kw)
        Plugin.registry.append(cls)
class A(Plugin): pass
class B(Plugin): pass
print([c.__name__ for c in Plugin.registry])

When NOT to Override

Don't override if you don't need to change behavior. Unnecessary overrides create maintenance burden. Prefer composition for unrelated behavior.
# Good: only override what's needed
class Dog(Animal):
    def speak(self): return 'Woof'
    # No need to override __init__ if parent's is fine
print('override guidance')

Quick Check

In Python 3, what does super() (with no arguments) refer to inside a method?

Recap

Override by redefining in child. super().method() calls the parent version. super().__init__() initializes the parent. Cooperative super() follows MRO order.

Keep Going

Excellent progress! Keep going to master the next concept.

Frequently asked questions

Is the “Method Overriding and super()” lesson free?

Yes — the full text of “Method Overriding and super()” 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 “Method Overriding and super()”?

Override parent methods and call them with super(). 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Method Overriding and super()” 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

  1. Single Inheritance
  2. Method Overriding and super()
  3. Multiple Inheritance and MRO
  4. Polymorphism and Duck Typing
← Back to Python Academy