What’s New ?

The Top 10 favtutor Features You Might Have Overlooked

Read More
Computer Science

Inheritance in Python (All 5 Types) with Examples

Jul 19, 2026 6 Minutes Read Why Trust Us Why you can trust this guide. Written by working engineers and reviewed by our editorial team under a strict editorial policy for accuracy, clarity and zero bias. Kusum Jain By Kusum Jain Kusum Jain Kusum Jain
I am an avid coder on CodeChef, I partake in hackathons regularly. I am an independent and self-motivated student with a love for coding and experiencing new things.
Inheritance in Python (All 5 Types) with Examples

In Python, inheritance is a mechanism where a class receives the attributes and methods of another class. The class being inherited from is the parent (or base) class, and the class that inherits is the child (or derived) class.

Python supports five types of inheritance: single, multiple, multilevel, hierarchical, and hybrid. This lesson defines each type with a runnable example and a diagram, then covers the tools you use with inheritance: super(), method overriding, and isinstance().

What Is Inheritance in Python?

Inheritance lets a child class reuse the code of a parent class by listing the parent in parentheses in the class definition.

# 1. A parent class
class Employee:
    def __init__(self, name):
        self.name = name

    def introduce(self):
        return f"{self.name} works here"

# 2. A child class that inherits from Employee
class Manager(Employee):
    pass

lena = Manager("Lena")
print(lena.introduce())  # Outputs: Lena works here

Manager defines nothing of its own, yet it has __init__() and introduce() because it inherits them from Employee.

Inheritance in Python: a Manager child class receives the __init__ and introduce methods of the Employee parent class

5 Types of Inheritance in Python

Python has five types of inheritance, classified by how many parents and levels are involved.

1) Single Inheritance in Python

One child class inherits from one parent class. This is the most common form.

class Account:
    def __init__(self, owner):
        self.owner = owner

class SavingsAccount(Account):
    def add_interest(self):
        return f"Interest added for {self.owner}"

acct = SavingsAccount("[email protected]")
print(acct.add_interest())  # Outputs: Interest added for [email protected]

2) Multiple Inheritance in Python

One child class inherits from two or more parent classes and combines their behavior.

class Camera:
    def take_photo(self):
        return "photo saved"

class Phone:
    def make_call(self, number):
        return f"calling {number}"

class Smartphone(Camera, Phone):
    pass

pixel = Smartphone()
print(pixel.take_photo())           # Outputs: photo saved
print(pixel.make_call("555-0142"))  # Outputs: calling 555-0142

When two parents define the same method name, Python uses the parent listed first. The order is decided by the method resolution order, covered later in this lesson.

3) Multilevel Inheritance in Python

A class inherits from a child class, forming a chain. Each level adds to what it received from the level above.

class Vehicle:
    wheels = 4

class Car(Vehicle):
    doors = 4

class ElectricCar(Car):
    battery_kwh = 75

model3 = ElectricCar()
print(model3.wheels, model3.doors, model3.battery_kwh)  # Outputs: 4 4 75

4) Hierarchical Inheritance in Python

Two or more child classes inherit from the same parent class.

class Employee:
    def __init__(self, name):
        self.name = name

class Designer(Employee):
    tool = "figma"

class Developer(Employee):
    tool = "vscode"

asha = Designer("asha")
marco = Developer("marco")
print(asha.tool, marco.tool)  # Outputs: figma vscode

5) Hybrid Inheritance in Python

A combination of two or more of the types above in one class hierarchy. The example below mixes hierarchical inheritance (two classes inherit from Device) with multiple inheritance (Convertible inherits from both).

class Device:
    powered = True

class Laptop(Device):
    portable = True

class Tablet(Device):
    touchscreen = True

class Convertible(Laptop, Tablet):
    pass

surface = Convertible()
print(surface.powered, surface.portable, surface.touchscreen)  # Outputs: True True True
Diagrams of the five types of inheritance in Python: single, multiple, multilevel, hierarchical, and hybrid

How to Use Inheritance in Python

1) The super() Function

The super() function calls a method from the parent class. It is most often used in __init__() so the child can extend the parent's setup instead of repeating it.

class Employee:
    def __init__(self, name):
        self.name = name

class Manager(Employee):
    def __init__(self, name, team_size):
        super().__init__(name)
        self.team_size = team_size

raj = Manager("Raj", 8)
print(raj.name, raj.team_size)  # Outputs: Raj 8

2) Method Overriding

A child class overrides a method by defining one with the same name. Python then calls the child's version.

class Notifier:
    def send(self, message):
        return f"log: {message}"

class EmailNotifier(Notifier):
    def send(self, message):
        return f"email sent: {message}"

alerts = EmailNotifier()
print(alerts.send("invoice ready"))  # Outputs: email sent: invoice ready

3) Overriding and Extending Together

An overridden method can still call the parent's version with super(). The child then adds behavior around the parent's result instead of replacing it.

class Logger:
    def log(self, event):
        return f"[app] {event}"

class TimedLogger(Logger):
    def log(self, event):
        base = super().log(event)
        return f"{base} at 14:05"

audit = TimedLogger()
print(audit.log("user signed in"))  # Outputs: [app] user signed in at 14:05

4) isinstance() and issubclass()

isinstance() checks whether an object belongs to a class or any of its parents, and issubclass() checks the relationship between two classes.

class Employee:
    pass

class Designer(Employee):
    pass

asha = Designer()
print(isinstance(asha, Employee))      # Outputs: True
print(issubclass(Designer, Employee))  # Outputs: True

When to Use Inheritance in Python

1) An Is-a Relationship

Inheritance fits when the child genuinely is a kind of the parent: a SavingsAccount is an Account, a Designer is an Employee. If the relationship is has-a rather than is-a, store the other object as an attribute instead (composition).

2) Shared Behavior Across Related Classes

When several classes need the same methods, moving them into one parent removes the duplication, and a fix in the parent reaches every child.

3) Specializing an Existing Class

A child class can keep most of a parent's behavior and override only the parts that differ, as EmailNotifier did with send().

Examples of Inheritance in Python

1) User Roles with an Overridden Permission

class User:
    def __init__(self, email):
        self.email = email

    def can_edit(self):
        return False

class Admin(User):
    def can_edit(self):
        return True

print(User("[email protected]").can_edit())   # Outputs: False
print(Admin("[email protected]").can_edit())  # Outputs: True

2) A Shape Parent with a Specialized Child

class Shape:
    def describe(self):
        return "a shape"

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return 3.14159 * self.radius ** 2

wheel = Circle(3)
print(wheel.describe())       # Outputs: a shape
print(round(wheel.area(), 2)) # Outputs: 28.27

Learn More About Python Inheritance

Method Resolution Order (MRO)

With multiple parents, Python decides where to look for a method using the method resolution order. The __mro__ attribute shows the exact search path, which follows the C3 linearization algorithm.

class Device:
    pass

class Laptop(Device):
    pass

class Tablet(Device):
    pass

class Convertible(Laptop, Tablet):
    pass

for cls in Convertible.__mro__:
    print(cls.__name__)
# Outputs:
# Convertible
# Laptop
# Tablet
# Device
# object
Method resolution order for a diamond-shaped hybrid inheritance hierarchy in Python, searched from Convertible to Laptop to Tablet to Device

Inheriting From a Built-in Class

Built-in types such as list and dict can be parent classes too. The child keeps every list method and adds its own.

class Playlist(list):
    def total(self):
        return f"{len(self)} tracks"

mix = Playlist(["midnight city", "on melancholy hill"])
mix.append("weightless")
print(mix.total())  # Outputs: 3 tracks

The object Base Class

Every Python class inherits from object, directly or through its parents. That is why object appears at the end of every MRO and why all classes have methods such as __str__().

Inheritance vs Composition

Composition stores another object as an attribute instead of inheriting from its class. A Car has an Engine, so composition is the fit; an ElectricCar is a Car, so inheritance is. Composition keeps classes independent, which is the safer default when the is-a test fails.

Key Takeaways for Inheritance in Python

  • Definition - a child class listed as class Child(Parent) receives the parent's attributes and methods.
  • Five types - single, multiple, multilevel, hierarchical, and hybrid, classified by the number of parents and levels.
  • super() - calls the parent's version of a method so the child can extend it instead of repeating it.
  • Overriding - a child method with the same name replaces the parent's; the MRO decides which version runs.
  • Is-a test - inherit only when the child is a kind of the parent; otherwise use composition.

Inheritance shapes what type an object reports at runtime. To inspect that from code, read our lesson on getting the class name of an instance in Python.

Kusum Jain
About the author

Kusum Jain

I am an avid coder on CodeChef, I partake in hackathons regularly. I am an independent and self-motivated student with a love for coding and experiencing new things.