37 - Types of Inheritance in Python

Опубликовано: 08 Апрель 2026
на канале: King of Techniques
141
7

#python #python3 #pythoncourse #inheritance
‪@kingoftechniques6864‬

Inheritance is the capability of one class to derive or inherit the properties from another class. The benefits of inheritance are:


It represents real-world relationships well.
It provides reusability of a code. We don’t have to write the same code again and again. Also, it allows us to add more features to a class without modifying it.
It is transitive in nature, which means that if class B inherits from another class A, then all the subclasses of B would automatically inherit from class A.

Types of Inheritance depends upon the number of child and parent classes involved. There are four types of inheritance in Python:


1- Single Inheritance:
Single inheritance enables a derived class to inherit properties from a single parent class, thus enabling code reusability and the addition of new features to existing code.

2- Multiple Inheritance:
When a class can be derived from more than one base class this type of inheritance is called multiple inheritance. In multiple inheritance, all the features of the base classes are inherited into the derived class.

3- Multilevel Inheritance:
In multilevel inheritance, features of the base class and the derived class are further inherited into the new derived class. This is similar to a relationship representing a child and grandfather.

4- Hierarchical Inheritance:
When more than one derived classes are created from a single base this type of inheritance is called hierarchical inheritance. In this program, we have a parent (base) class and two child (derived) classes.