Python inheritance is one of the most powerful concepts in object-oriented programming (OOP). It allows a class (called a child class or subclass) to inherit attributes and methods from another class (called a parent class or superclass). With inheritance, you can write cleaner, reusable, and more efficient code.
In this article, we will explore the fundamentals of inheritance in Python, including types of inheritance, how to override methods, and how to use the super() function. By the end, you will understand how inheritance helps build scalable Python applications.

1. What Is Inheritance in Python?
Inheritance enables one class to access the properties and behaviors of another class. This helps developers follow the DRY (Don’t Repeat Yourself) principle and avoid redundant code.
Here’s a simple example to demonstrate inheritance in Python:
# Base class (Parent)
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return "Some sound"
# Derived class (Child)
class Dog(Animal):
def speak(self):
return "Woof!"
# Another derived class
class Cat(Animal):
def speak(self):
return "Meow!"
# Creating objects
dog = Dog("Buddy")
cat = Cat("Whiskers")
print(dog.name, "says", dog.speak())
print(cat.name, "says", cat.speak())
Output:
Buddy says Woof! Whiskers says Meow!
In the code above, both Dog and Cat inherit from the Animal class but override the speak() method to define their own sounds.
2. Why Use Inheritance?
Inheritance helps in several ways:
- Code Reusability: You can reuse the code of the parent class in child classes.
- Maintainability: If you modify code in the base class, all child classes automatically reflect those changes.
- Scalability: Easier to extend functionality without rewriting everything.
- Polymorphism: The same method name can behave differently depending on the class.
3. Single Inheritance Example
Single inheritance occurs when a child class inherits from one parent class.
class Vehicle:
def move(self):
print("Vehicle is moving")
class Car(Vehicle):
def honk(self):
print("Car honks: Beep beep!")
# Testing
car = Car()
car.move() # Inherited from Vehicle
car.honk() # Defined in Car
Output:
Vehicle is moving Car honks: Beep beep!
4. Multiple Inheritance Example
In multiple inheritance, a class can inherit from more than one parent class. Python supports this with a left-to-right method resolution order (MRO).
class Father:
def skill(self):
print("Father: Driving")
class Mother:
def skill(self):
print("Mother: Cooking")
class Child(Father, Mother):
def hobby(self):
print("Child: Playing football")
# Test
c = Child()
c.skill() # Follows MRO, so it calls Father's skill()
c.hobby()
Output:
Father: Driving Child: Playing football
Python uses the Method Resolution Order (MRO) to decide which method to call when multiple parents define the same method. You can check MRO with Child.mro().
5. Multilevel Inheritance Example
In multilevel inheritance, a child class inherits from another child class, forming a chain of inheritance.
class Grandfather:
def garden(self):
print("Grandfather loves gardening")
class Father(Grandfather):
def drive(self):
print("Father drives a car")
class Son(Father):
def play(self):
print("Son plays video games")
# Test
son = Son()
son.garden()
son.drive()
son.play()
Output:
Grandfather loves gardening Father drives a car Son plays video games
6. Using the super() Function
The super() function allows you to call methods of the parent class without explicitly naming it. This is especially useful when working with multilevel or multiple inheritance structures.
class Animal:
def __init__(self, name):
self.name = name
def info(self):
print(f"Animal name: {self.name}")
class Dog(Animal):
def __init__(self, name, breed):
super().__init__(name)
self.breed = breed
def info(self):
super().info()
print(f"Breed: {self.breed}")
dog = Dog("Buddy", "Golden Retriever")
dog.info()
Output:
Animal name: Buddy Breed: Golden Retriever
7. Method Overriding in Inheritance
When a method in a child class has the same name as a method in the parent class, it overrides the parent’s method. This allows the child class to provide a new implementation while maintaining the same method interface.
class Bird:
def fly(self):
print("Birds can fly")
class Penguin(Bird):
def fly(self):
print("Penguins cannot fly")
penguin = Penguin()
penguin.fly()
Output:
Penguins cannot fly
8. Checking Class Relationships
Python provides built-in functions to check inheritance relationships:
issubclass(Sub, Super)→ ReturnsTrueif a class is derived from another.isinstance(obj, Class)→ ReturnsTrueif an object is an instance of a class or its subclass.
print(issubclass(Dog, Animal)) # True print(isinstance(dog, Dog)) # True print(isinstance(dog, Animal)) # True
9. Advantages of Using Inheritance in Python
- Improved code reusability — share common functionality between classes.
- Organized code structure — helps to manage large-scale projects easily.
- Extensibility — easily add new features to derived classes.
- Polymorphism — one interface for different data types.
10. Common Mistakes to Avoid
- Forgetting to use
super().__init__()when overriding constructors. - Creating deep inheritance chains that are hard to maintain.
- Not using composition when it’s a better choice than inheritance.
Conclusion
Inheritance is a core feature of Python’s object-oriented programming. By understanding and applying it correctly, you can write efficient, reusable, and clean code. You can use super(), method overriding, and multiple inheritance to structure your programs logically.
Practice creating your own parent and child classes to master the basics of Python inheritance. Once you’re comfortable, you can explore advanced OOP concepts like abstract classes, interfaces, and mixins.
Mastering inheritance will make your Python code more maintainable and scalable — an essential skill for every developer.