Python Inheritance Tutorial for Beginners | Single, Multiple & Multilevel Inheritance
One of the biggest advantages of Object-Oriented Programming is the ability to reuse existing code instead of writing everything from scratch. Inheritance allows one class to inherit the properties and methods of another class, making applications more organized, maintainable, and scalable.
Inheritance is widely used in enterprise applications, banking systems, hospital management software, e-commerce platforms, Artificial Intelligence projects, and web frameworks like Django. It reduces code duplication and enables developers to build applications using a parent-child relationship.
In this lesson, you’ll learn different types of inheritance in Python, how to inherit properties and methods from parent classes, use the super() function, override methods, and build real-world applications using inheritance.
By the end of this lesson, you’ll be able to create reusable class hierarchies and write cleaner Object-Oriented Python code.
Learning Objectives
After completing this lesson, you will be able to:
- Understand the concept of inheritance.
- Create parent and child classes.
- Implement single inheritance.
- Understand multiple inheritance.
- Learn multilevel inheritance.
- Explore hierarchical inheritance.
- Use the
super()function. - Override inherited methods.
- Apply inheritance in real-world applications.
Topics Covered
- What is Inheritance?
- Parent and Child Classes
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Method Overriding
- super() Function
- Real-World Examples
- Best Practices
Detailed Lesson Content
Introduction to Inheritance
Imagine you’re developing a School Management System.
Every person in the school has common information:
- Name
- Mobile Number
However, there are different types of users:
- Students
- Teachers
- Administrators
Instead of writing the same attributes repeatedly in each class, we create one Person class and allow the other classes to inherit from it.
This is called Inheritance.
Inheritance allows one class (called the Child Class) to acquire the properties and methods of another class (called the Parent Class).
Why Do We Need Inheritance?
Without inheritance:
- Duplicate code increases.
- Maintenance becomes difficult.
- Updating common functionality requires changes in multiple places.
With inheritance:
- Code becomes reusable.
- Maintenance becomes easier.
- Applications become scalable.
- Development becomes faster.
- Code follows the DRY (Don’t Repeat Yourself) principle.
Parent Class and Child Class
The class being inherited is called the Parent Class (or Base Class).
The class that inherits is called the Child Class (or Derived Class).
Example:
class Person:
def display(self):
print("I am a Person")
class Student(Person):
pass
student = Student()
student.display()
Output
I am a Person
Although display() is not defined inside Student, it can still use the method inherited from Person.
Single Inheritance
Single inheritance means one child class inherits from one parent class.
Example:
class Animal:
def sound(self):
print("Animals make sounds")
class Dog(Animal):
def bark(self):
print("Dog Barks")
dog = Dog()
dog.sound()
dog.bark()
Output
Animals make sounds
Dog Barks
Single inheritance is the most commonly used type of inheritance.
Multiple Inheritance
A class can inherit from more than one parent class.
Example:
class Camera:
def photo(self):
print("Take Photo")
class Phone:
def call(self):
print("Calling")
class SmartPhone(Camera, Phone):
pass
mobile = SmartPhone()
mobile.photo()
mobile.call()
Output
Take Photo
Calling
Python supports multiple inheritance, allowing a class to combine features from multiple parent classes.
Multilevel Inheritance
In multilevel inheritance, a child class becomes the parent of another class.
Example:
class Person:
def display(self):
print("Person")
class Employee(Person):
def work(self):
print("Working")
class Manager(Employee):
def manage(self):
print("Managing Team")
manager = Manager()
manager.display()
manager.work()
manager.manage()
Output
Person
Working
Managing Team
Hierarchical Inheritance
One parent class has multiple child classes.
Example:
class Vehicle:
def start(self):
print("Vehicle Started")
class Car(Vehicle):
pass
class Bike(Vehicle):
pass
car = Car()
bike = Bike()
car.start()
bike.start()
Output
Vehicle Started
Vehicle Started
Hybrid Inheritance
Hybrid inheritance combines two or more types of inheritance.
Although Python supports hybrid inheritance, it should be used carefully because it can make applications difficult to understand and maintain.
The super() Function
The super() function allows a child class to call methods or constructors of the parent class.
Example:
class Person:
def __init__(self,name):
self.name = name
class Student(Person):
def __init__(self,name,course):
super().__init__(name)
self.course = course
student = Student("Rahul","Python")
print(student.name)
print(student.course)
Output
Rahul
Python
Using super() avoids rewriting parent class initialization code.
Method Overriding
Sometimes the child class needs different behavior than the parent class.
Example:
class Animal:
def sound(self):
print("Animal Sound")
class Dog(Animal):
def sound(self):
print("Dog Barks")
dog = Dog()
dog.sound()
Output
Dog Barks
The child class overrides the parent’s sound() method.
Real-World Example 1: Employee Management System
class Employee:
def __init__(self,name):
self.name = name
def work(self):
print("Employee Working")
class Developer(Employee):
def code(self):
print("Writing Python Code")
developer = Developer("Rahul")
developer.work()
developer.code()
Real-World Example 2: Banking System
class BankAccount:
def deposit(self):
print("Deposit Successful")
class SavingsAccount(BankAccount):
def interest(self):
print("Interest Added")
account = SavingsAccount()
account.deposit()
account.interest()
Real-World Example 3: E-Commerce Products
class Product:
def details(self):
print("Product Details")
class Laptop(Product):
def specifications(self):
print("16GB RAM")
laptop = Laptop()
laptop.details()
laptop.specifications()
Real-World Example 4: Hospital Management
class Person:
def login(self):
print("Login Successful")
class Doctor(Person):
def prescribe(self):
print("Prescription Created")
doctor = Doctor()
doctor.login()
doctor.prescribe()
Common Mistakes
Forgetting Parentheses During Inheritance
Incorrect
class Student:
Correct
class Student(Person):
Not Calling Parent Constructor
Incorrect
class Student(Person):
def __init__(self,name):
self.name = name
Better
class Student(Person):
def __init__(self,name):
super().__init__(name)
Overriding Without Need
Avoid overriding methods unless the child class truly needs different behavior.
Best Practices
- Design a meaningful parent class.
- Avoid unnecessary inheritance.
- Use
super()to initialize parent classes. - Follow the “is-a” relationship (e.g., Dog is an Animal).
- Prefer composition over inheritance when appropriate.
- Keep inheritance hierarchies simple.
- Override methods only when necessary.
Key Takeaways
- Inheritance promotes code reuse.
- A child class inherits properties and methods from a parent class.
- Python supports single, multiple, multilevel, hierarchical, and hybrid inheritance.
super()allows access to parent class methods and constructors.- Method overriding enables customized behavior.
- Inheritance helps build scalable and maintainable software.



