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
Overriding Basics
class Greeter:
def greet(self): return 'Hello'
class FormalGreeter(Greeter):
def greet(self): return 'Good day'
print(FormalGreeter().greet())super() in Overrides
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__
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
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
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__
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
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
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__
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
# 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
Recap
Keep Going
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
- Single Inheritance
- Method Overriding and super()
- Multiple Inheritance and MRO
- Polymorphism and Duck Typing