Last modified: Dec 01, 2026
Types of Python Inheritance
Inheritance lets one Python class reuse the code of another class. It is a core idea in object-oriented programming. This guide covers every major type of inheritance in Python.
The topic can feel abstract at first. We keep each section short and practical. Every type comes with a code example and its output.
If you want a gentle overview before diving in, read Inheritance in Python Explained. It sets the stage for the details below.
What Is Inheritance?
Inheritance creates a parent-child link between classes. The child class gets the methods and attributes of the parent class.
The parent is often called the base class. The child is often called the derived class or subclass.
Python supports several inheritance patterns. The most common are single, multiple, multilevel, hierarchical, and hybrid inheritance.
Python also allows many inheritance setups that other languages block. This flexibility is powerful. It also means you should choose the simplest pattern that works.
1. Single Inheritance
Single inheritance means one child class inherits from one parent class. It is the simplest and most common form.
The child can add new methods. It can also override methods from the parent.
class Animal:
def speak(self):
return "Some sound"
class Dog(Animal): # Dog inherits from Animal
def speak(self):
return "Woof"
dog = Dog()
print(dog.speak())
Woof
The speak method is overridden in the child class. The parent version is replaced for `Dog` objects.
Single inheritance keeps class trees easy to read. Beginners should start here. For the basics of creating classes, see Python Class Basics for Beginners.
2. Multiple Inheritance
Multiple inheritance means one child class inherits from more than one parent class. Python supports this directly.
The child can combine behavior from several base classes. This is handy but can get complex.
class Swimmer:
def swim(self):
return "Swimming"
class Flyer:
def fly(self):
return "Flying"
class Duck(Swimmer, Flyer): # Inherits from two classes
pass
duck = Duck()
print(duck.swim())
print(duck.fly())
Swimming
Flying
The `Duck` class gets methods from both parents. Python uses the MRO (Method Resolution Order) to decide which method wins when names clash.
Multiple inheritance is powerful. Use it only when the combined classes are truly independent. Deep mixing can confuse readers.
3. Multilevel Inheritance
Multilevel inheritance forms a chain. A class inherits from a child class, which inherits from a parent class.
Each level can add or change behavior. The bottom class inherits from all levels above it.
class Vehicle:
def move(self):
return "Moving"
class Car(Vehicle):
def wheels(self):
return "Four wheels"
class SportsCar(Car): # Inherits from Car, which inherits from Vehicle
def speed(self):
return "Very fast"
car = SportsCar()
print(car.move())
print(car.wheels())
print(car.speed())
Moving
Four wheels
Very fast
The `SportsCar` class reaches methods two levels up. The chain stays clear as long as each class adds a focused feature.
Long chains can become hard to trace. Keep them shallow when possible.
4. Hierarchical Inheritance
Hierarchical inheritance means several child classes inherit from one parent class. The parent is shared.
Each child can add its own methods. The shared parent holds common behavior.
class Shape:
def describe(self):
return "I am a shape"
class Circle(Shape):
def area(self):
return "Circle area"
class Square(Shape):
def area(self):
return "Square area"
print(Circle().describe())
print(Square().describe())
I am a shape
I am a shape
Both children reuse the `describe` method. This avoids duplicate code across related classes.
Hierarchical inheritance is common in frameworks. It groups shared logic in one base class.
5. Hybrid Inheritance
Hybrid inheritance mixes two or more of the types above. A common case combines multiple and multilevel inheritance.
Python allows this. The MRO keeps method lookup consistent.
class A:
def show(self):
return "A"
class B(A):
pass
class C(A):
pass
class D(B, C): # Combines multilevel and multiple
pass
print(D().show())
print(D.__mro__)
A
(, , , , )
The MRO prints the lookup order. Python checks `D`, then `B`, then `C`, then `A`.
Hybrid designs can be elegant. They can also be hard to debug. Prefer clear, shallow trees.
Using super() in Inheritance
The super function calls a method from the parent class. It is common inside __init__.
This keeps parent setup intact when a child adds its own setup.
class Person:
def __init__(self, name):
self.name = name
class Student(Person):
def __init__(self, name, grade):
super().__init__(name) # Calls parent __init__
self.grade = grade
s = Student("Ana", 10)
print(s.name, s.grade)
Ana 10
Without `super`, the parent setup would be skipped. The child would miss the `name` attribute.
For a smoother walkthrough of class setup, try Python Inheritance Made Simple.
The Role of Dunder Methods
Inheritance also affects special methods. Dunder methods like __str__ and __repr__ are inherited too.
Children can override them to change how objects print or compare.
class Base:
def __str__(self):
return "Base object"
class Child(Base):
pass
print(Child())
Base object
The child inherits the parent's `__str__`. Overriding it would give a custom message.
For a full reference, see the Python Dunder Methods List. It pairs well with this guide.
Best Practices for Python Inheritance
Use inheritance only for true "is-a" relationships. A `Dog` is an `Animal`. That fits.
Avoid deep trees. Keep each class focused on one job.
Prefer composition when behavior is shared but the relationship is not a clear subtype.
Document the MRO when using multiple inheritance. Future readers will thank you.
Test parent and child behavior separately. This catches override mistakes early.
Common Mistakes
Forgetting to call `super().__init__` is a frequent bug. The parent setup never runs.
Name clashes in multiple inheritance can surprise you. Check the MRO when results look odd.
Overriding a method with the same name but a different purpose can confuse callers. Keep overrides consistent with the parent contract.
Conclusion
Python offers five main inheritance types. They are single, multiple, multilevel, hierarchical, and hybrid.
Each type solves a different design problem. Start with single inheritance. Add complexity only when the code truly needs it.
Watch the MRO in multiple inheritance. Use `super` to keep parent setup working. Keep class trees shallow and clear.
With these habits, inheritance becomes a clean tool instead of a source of confusion.