super()
Call parent class methods from a child class — the right way to extend inherited behaviour without duplicating code.
"super() means 'go up one level in the class hierarchy and use that version'. It keeps your code DRY and makes inheritance actually useful."
— ShurAIWhat is super()?
super() returns a proxy object that gives you access to the parent class’s methods. It is most commonly used in two places:
super().__init__(...)
super().method_name()
super() in __init__
class Vehicle:
def __init__(self, make, speed):
self.make = make
self.speed = speed
class Car(Vehicle):
def __init__(self, make, speed, doors):
super().__init__(make, speed) # sets self.make and self.speed
self.doors = doors # add Car's own attribute
c = Car("Toyota", 180, 4)
print(c.make) # Toyota — set by Vehicle.__init__ via super()
print(c.doors) # 4 — set by Car.__init__
Without super() — What Goes Wrong
class Car(Vehicle):
def __init__(self, make, speed, doors):
self.make = make # duplicated from Vehicle!
self.speed = speed # duplicated from Vehicle!
self.doors = doors
# If Vehicle.__init__ ever changes, Car breaks silently.
# Always use super() instead.
super() in an Overridden Method
class Logger:
def log(self, msg):
print(f"[LOG] {msg}")
class TimestampLogger(Logger):
def log(self, msg):
from datetime import datetime
ts = datetime.now().strftime("%H:%M:%S")
super().log(f"[{ts}] {msg}") # extend, not replace
TimestampLogger().log("App started")
# [LOG] [14:22:07] App started
Multi-Level Inheritance
super() always goes up exactly one level, so it works cleanly in chains:
class A:
def greet(self): print("Hello from A")
class B(A):
def greet(self):
super().greet() # calls A.greet()
print("Hello from B")
class C(B):
def greet(self):
super().greet() # calls B.greet() which calls A.greet()
print("Hello from C")
C().greet()
# Hello from A
# Hello from B
# Hello from C
"Always call super().__init__() first in a child's __init__ before setting your own attributes. Otherwise you might overwrite something the parent just set up."
— ShurAI🧠 Quiz — Q1
What does super() return?
🧠 Quiz — Q2
Why call super().__init__() inside a child's __init__?
🧠 Quiz — Q3
In class Car(Vehicle), what does super().__init__(make, speed) do?
🧠 Quiz — Q4
When is it better to use super().method() than to fully override a method?