How does inheritance work in Python, and what does super() do?
Reviewed by Gurusankar M.
Short Answer
A subclass inherits attributes/methods from a parent and can add or override them. `super()` calls the parent's version of a method — most often in `__init__` to initialize the inherited part before adding subclass-specific state. Python resolves method lookup via the MRO (Method Resolution Order).
On this page
Concept Made Simple
Coffee Chat Question
“How does inheritance work in Python, and what does super() do?”
Remember It Faster
Mind Map Answer
- Subclass
- class Dog(Animal)
- Override
- redefine a parent method
- super()
- call the parent's method
- MRO
- lookup order (C3 linearization)
Learn by Doing
Hands-on Keyboard
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return "..."
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name) # init parent part
self.breed = breed
def speak(self):
return "Woof"
d = Dog("Rex", "Lab")
print(d.name, d.speak())Rex Woof
Think Beyond the Expected
What If?
Why call super().__init__() instead of Parent.__init__(self)?
super() follows the MRO, so in multiple-inheritance hierarchies each parent's __init__ runs exactly once in the correct order — hard-coding Parent.__init__ can skip or double-call ancestors. super() is also refactor-safe: rename the base class and it still works.
Real World
Framework classes (Django views, exceptions, custom errors) are extended by subclassing and calling super() to reuse base behavior while adding your own — the backbone of code reuse in OOP Python.
Interviewer's Expectation
Keywords they're listening for:
- subclass inherits/overrides
- super() calls parent
- init the inherited part
- MRO resolves lookup
- prefer super over hardcoding parent
Common Mistakes
- Forgetting super().__init__() (uninitialized parent state)
- Hardcoding Parent.__init__ in multi-inheritance
- Overusing deep inheritance instead of composition
Best Practices
- Use super() for parent initialization/methods
- Prefer composition over deep hierarchies
- Keep overrides consistent with the parent contract
Follow-up Questions
- What is the MRO and how do you view it (__mro__)?
- How does Python handle multiple inheritance / diamond problem?
- Composition vs inheritance — when each?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Inheritance (Python) Interview question: "How does inheritance work in Python, and what does super() do?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair