Programming
Inheritance and Its Type with Python
Concepts of Single, Multilevel, and Multiple inheritance methods
Inheritance is a method in object-oriented programming to make subclass similar to the main classes so that the subclass inherits properties from main classes. The main reason why we use inheritance is the re-usability of code.
Types of inheritance
- Single Inheritance
- Multilevel Inheritance
- Multiple Inheritance
Single inheritance
Single inheritance means when a subclass inherits properties from only one main class. For example, we can take the properties of the house.

Example:
class A:
def area(self):
print("Housing price depends on area size")
def kitchen(self):
print("The kitechen should be madular type")
#now making a class B, which inherits the properties of class A
class B(A):
def parking(self):
print("Need of space for two cars")
def garden(self):
print("Garden should be in house")To access the methods or functions or features of classes we have to make an object of that class.
#to access their features we make an object of class
a = A()Small ‘a’ is an object of class A and with this object, we can access methods of that class. Press tab after the dot. you can see all the features you can use from that class.
a.area()

The output of using the object.

When we make an object of class B we see that it inherit all methods of class A also.
b = B() b.parking()

Multilevel Inheritance
In multilevel inheritance, the more subclass is derived from the subclass. To understand this there is a diagram below.

Example:
class A:
def area(self):
print("Housing price depends on area size")
def kitchen(self):
print("The kitchen should be modular type")
#now making a class B, which inherits the properties of class A
class B(A):
def parking(self):
print("Need of space for two cars")
def garden(self):
print("Garden should be in house")
#deriving class C for multilevel inheritance
class C(B):
def trees(self):
print("Happy Environment Day")
def happy(self):
print("We are happy people")
#to access their features we make an object of class
c = C()
c.happy()That’s how class ‘C’ is inheriting the features of class ‘B’.

Multilevel Inheritance
In this type of inheritance, the subclass is inheriting the features from class A and class B means inheriting from more than one main classes. One point is to be noticed that Class b is not inheriting from class A.

Example:
class A:
def area(self):
print("Housing price depends on area size")
def kitchen(self):
print("The kitchen should be modular type")
#now making a class B, which inherits the properties of class A
class B:
def parking(self):
print("Need of space for two cars"
def garden(self):
print("Garden should be in house")
#deriving class C for multiple inheritance
class C(A,B):
def trees(self):
print("Happy Environment Day")
def happy(self):
print("We are happy people")
#to access their features we make an object of class
c = C()
c.trees()Conclusion:
Inheritance is a very important concept in object-oriented programming for easy-to-use and re-usability of code.
I hope you like the article. Reach me on my LinkedIn and twitter.
Recommended Articles
1. 15 Most Usable NumPy Methods with Python 2. NumPy: Linear Algebra on Images 3. Exception Handling Concepts in Python 4. Pandas: Dealing with Categorical Data 5. Hyper-parameters: RandomSeachCV and GridSearchCV in Machine Learning 6. Fully Explained Linear Regression with Python 7. Fully Explained Logistic Regression with Python 8. Data Distribution using Numpy with Python 9. 40 Most Insanely Usable Methods in Python 10. 20 Most Usable Pandas Shortcut Methods in Python
