
- Python - Home
- Python - Overview
- Python - History
- Python - Features
- Python vs C++
- Python - Hello World Program
- Python - Application Areas
- Python - Interpreter
- Python - Environment Setup
- Python - Virtual Environment
- Python - Basic Syntax
- Python - Variables
- Python - Private Variables
- Python - Data Types
- Python - Type Casting
- Python - Unicode System
- Python - Literals
- Python - Operators
- Python - Arithmetic Operators
- Python - Comparison Operators
- Python - Assignment Operators
- Python - Logical Operators
- Python - Bitwise Operators
- Python - Membership Operators
- Python - Identity Operators
- Python - Walrus Operator
- Python - Operator Precedence
- Python - Comments
- Python - User Input
- Python - Numbers
- Python - Booleans
- Python - Floating Points
- Python - Control Flow
- Python - Decision Making
- Python - If Statement
- Python - If else
- Python - Nested If
- Python - Match-Case Statement
- Python - Loops
- Python - for Loops
- Python - for-else Loops
- Python - While Loops
- Python - break Statement
- Python - continue Statement
- Python - pass Statement
- Python - Nested Loops
- Python Functions & Modules
- Python - Functions
- Python - Default Arguments
- Python - Keyword Arguments
- Python - Keyword-Only Arguments
- Python - Positional Arguments
- Python - Positional-Only Arguments
- Python - Arbitrary Arguments
- Python - Variables Scope
- Python - Function Annotations
- Python - Modules
- Python - Packing and Unpacking
- Python - Built in Functions
- Python Strings
- Python - Strings
- Python - Slicing Strings
- Python - Modify Strings
- Python - String Concatenation
- Python - String Formatting
- Python - Escape Characters
- Python - String Methods
- Python - String Exercises
- Python Lists
- Python - Lists
- Python - Access List Items
- Python - Change List Items
- Python - Add List Items
- Python - Remove List Items
- Python - Loop Lists
- Python - List Comprehension
- Python - Sort Lists
- Python - Copy Lists
- Python - Join Lists
- Python - List Methods
- Python - List Exercises
- Python Tuples
- Python - Tuples
- Python - Access Tuple Items
- Python - Update Tuples
- Python - Unpack Tuples
- Python - Loop Tuples
- Python - Join Tuples
- Python - Tuple Methods
- Python - Namedtuple
- Python - Tuple Exercises
- Python Sets
- Python - Sets
- Python - Access Set Items
- Python - Add Set Items
- Python - Remove Set Items
- Python - Loop Sets
- Python - Join Sets
- Python - Copy Sets
- Python - Set Operators
- Python - Set Methods
- Python - Set Exercises
- Python Dictionaries
- Python - Dictionaries
- Python - Access Dictionary Items
- Python - Change Dictionary Items
- Python - Add Dictionary Items
- Python - Remove Dictionary Items
- Python - Dictionary View Objects
- Python - Loop Dictionaries
- Python - Copy Dictionaries
- Python - Nested Dictionaries
- Python - Dictionary Methods
- Python - Dictionary Exercises
- Python Arrays
- Python - Arrays
- Python - Access Array Items
- Python - Add Array Items
- Python - Remove Array Items
- Python - Loop Arrays
- Python - Copy Arrays
- Python - Reverse Arrays
- Python - Sort Arrays
- Python - Join Arrays
- Python - Array Methods
- Python - Array Exercises
- Python File Handling
- Python - File Handling
- Python - Write to File
- Python - Read Files
- Python - Renaming and Deleting Files
- Python - Directories
- Python - File Methods
- Python - OS File/Directory Methods
- Python - OS Path Methods
- Object Oriented Programming
- Python - OOPs Concepts
- Python - Classes & Objects
- Python - Class Attributes
- Python - Class Methods
- Python - Static Methods
- Python - Constructors
- Python - Access Modifiers
- Python - Inheritance
- Python - Multiple Inheritance
- Python - Multilevel Inheritance
- Python - Polymorphism
- Python - Method Overriding
- Python - Method Overloading
- Python - Dynamic Binding
- Python - Dynamic Typing
- Python - Abstraction
- Python - Encapsulation
- Python - Interfaces
- Python - Packages
- Python - Inner Classes
- Python - Anonymous Class and Objects
- Python - Singleton Class
- Python - Wrapper Classes
- Python - Enums
- Python - Reflection
- Python - Data Classes
- Python Errors & Exceptions
- Python - Syntax Errors
- Python - Exceptions
- Python - try-except Block
- Python - try-finally Block
- Python - Raising Exceptions
- Python - Exception Chaining
- Python - Nested try Block
- Python - User-defined Exception
- Python - Logging
- Python - Assertions
- Python - Warnings
- Python - Built-in Exceptions
- Python - Debugger (PDB)
- Python Multithreading
- Python - Multithreading
- Python - Thread Life Cycle
- Python - Creating a Thread
- Python - Starting a Thread
- Python - Joining Threads
- Python - Naming Thread
- Python - Thread Scheduling
- Python - Thread Pools
- Python - Main Thread
- Python - Thread Priority
- Python - Daemon Threads
- Python - Synchronizing Threads
- Python Synchronization
- Python - Inter-thread Communication
- Python - Thread Deadlock
- Python - Interrupting a Thread
- Python Networking
- Python - Networking
- Python - Socket Programming
- Python - URL Processing
- Python - Generics
- Python Libraries
- NumPy Tutorial
- Pandas Tutorial
- SciPy Tutorial
- Matplotlib Tutorial
- Django Tutorial
- OpenCV Tutorial
- Python Miscellenous
- Python - Date & Time
- Python - Maths
- Python - Iterators
- Python - Generators
- Python - Generator Expressions
- Python - Lambda Expressions
- Python - Closures
- Python - Decorators
- Python - Recursion
- Python - Reg Expressions
- Python - PIP
- Python - Database Access
- Python - Weak References
- Python - Serialization
- Python - Templating
- Python - Output Formatting
- Python - Performance Measurement
- Python - Data Compression
- Python - CGI Programming
- Python - XML Processing
- Python - GUI Programming
- Python - Command-Line Arguments
- Python - Docstrings
- Python - JSON
- Python - Sending Email
- Python - Further Extensions
- Python - Tools/Utilities
- Python - Odds and Ends
- Python - GUIs
- Python Advanced Concepts
- Python - Abstract Base Classes
- Python - Custom Exceptions
- Python - Higher Order Functions
- Python - Object Internals
- Python - Memory Management
- Python - Metaclasses
- Python - Metaprogramming with Metaclasses
- Python - Mocking and Stubbing
- Python - Monkey Patching
- Python - Signal Handling
- Python - Type Hints
- Python - Automation Tutorial
- Python - Humanize Package
- Python - Context Managers
- Python - Coroutines
- Python - Descriptors
- Python - Diagnosing and Fixing Memory Leaks
- Python - Immutable Data Structures
- Python Useful Resources
- Python - Questions & Answers
- Python - Interview Questions & Answers
- Python - Online Quiz
- Python - Quick Guide
- Python - Reference
- Python - Cheatsheet
- Python - Projects
- Python - Useful Resources
- Python - Discussion
- Python Compiler
- NumPy Compiler
- Matplotlib Compiler
- SciPy Compiler
Multi Level Inheritance in Python
Inheritance is a feature in object-oriented programming through which a class can inherit attributes and methods from another class. In Python, you can implement different types of inheritance, such as single inheritance, multiple inheritance, and multilevel inheritance. This chapter covers how to implement multilevel inheritance in Python.
Multilevel Inheritance in Python
Multilevel inheritance is a type of inheritance that happens hierarchically such that a derived class inherits from another derived class. Meaning, a class is derived from a class which is also derived from another class. This forms a chain of inheritance.
The class at the top of the chain is called the base class or parent class, the class in the middle is called the derived class or child class, and the class at the bottom of the chain is called the sub-derived class or sub-child class.
The following illustrations depicts the concept of multilevel inheritance −

Example of Multilevel Inheritance in Python
Let's look at an example to understand how multilevel inheritance works in Python −
# Base class class Network: def connectivity(self): return "Network connects" # Derived class class Network_5G(Network): def fast_connectivity(self): return "5G Network provides superfast connectivity" # Sub-derived class class Network_5G_Airtel(Network_5G): def fast_and_stable_connectivity(self): return "Airtel 5G network is fast and remains stable" # Creating an instance of Network_5G_Airtel network_object = Network_5G_Airtel() print(network_object.connectivity()) # Inherited from Network class print(network_object.fast_connectivity()) # Inherited from Network_5G class print(network_object.fast_and_stable_connectivity()) # Inherited from Network_5G_Airtel class
In this code, the Network_5G_Airtel class inherits the functions and attributes from the Network_5G class, which in turn inherits from the Network class. So the Network_5G_Airtel will have access to methods such as connectivity()(from Network), fast_connectivity()(from Network_5G), and fast_and_stable_connectivity()(from Network_5G_Airtel itself).
When you run the code, its output will be −
Network connects 5G Network provides superfast connectivity Airtel 5G network is fast and remains stable
MRO for Multilevel Inheritance in Python
Let's consider a scenario from the above example in which the Network_5G class also have a method named connectivity(). Now, What will happen if we call the connectivity() method from the instance of the Network_5G_Airtel class?. This is where the Method Resolution Order (MRO) comes into play.
Let's modify the previous example to include a connectivity() method in the Network_5G class −
# Base class class Network: def connectivity(self): return "Network connects" # Derived class class Network_5G(Network): def fast_connectivity(self): return "5G Network provides superfast connectivity" def connectivity(self): return "5G Network connects faster" # Sub-derived class class Network_5G_Airtel(Network_5G): def fast_and_stable_connectivity(self): return "Airtel 5G network is fast and remains stable" # Creating an instance of Network_5G_Airtel obj1 = Network_5G_Airtel() print(obj1.connectivity()) # Inherited from Network class
The output of the above code will be −
5G Network connects faster
This shows that the connectivity() method from the Network_5G class is called instead of the one from the Network class. This is because the method resolution order (MRO) in Python follows a depth-first approach, meaning it will first look for the method in the current class, then in the parent class, and so on up the hierarchy.
To know the method resolution order of any class, you can use the mro() method. Here's how you can do it:
print(Network_5G_Airtel.mro()) Output: [<class '__main__.Network_5G_Airtel'>, <class '__main__.Network_5G'>, <class '__main__.Network'>, <class 'object'>]
Overriding Methods in Multilevel Inheritance
In multilevel inheritance, a derived class can override methods of its parent class. Meaning, if a method is defined in both the parent class and the child class, the method in the child class will override the one in the parent class.
Here's an example to illustrate method overriding in multilevel inheritance −
# Base class class Vehicle: def start(self): return "Vehicle starts" # Derived class class Car(Vehicle): def start(self): return "Car starts" # Sub-derived class class SportsCar(Car): def start(self): return "Sports Car starts" # Creating an instance of SportsCar sports_car = SportsCar() print(sports_car.start()) # Calls the start method of SportsCar class
The output of the above code will be −
Sports Car starts
Conclusion
To conclude, multilevel inheritance is a type of inheritance where a class is derived from another derived class such that a chain of inheritance is formed. The method resolution order (MRO) will determine which method is called when there are methods with the same name in the inheritance chain. Method overriding can be performed to override the methods of the parent class in the child class.