Explain inheritance and its various types in python?

Table of Contents

Inheritance is concept where one class accesses the method and properties of another class. In this concept parent class is the class being inherited from, also called base class and child class is the class that inherits from another class, also called derived classes.

There are two types of interitance in python:

1. Multiple Inheritance

In multiple inheritance one child can inherit multiple parent classes. Lets say you have two classes, say A and B, and you wanted to create a new class which inherits the properties of both A and B then.

class A:
	# properties of class A
	# methods of calss B

class B:
	# properties of class A
	# methods of class B
class C(A , B):
	#class c inheriting property of both class A and B
	#add more properties to class C

2. Multilevel Inheritance

In this type of inheritance, the classes are inherited at multiple separate levels, lets takes three classes A , B and C, where A is the super class, B is its subchild class and C is the sub class of B.

Class A :
	# properties of class A

Class B(A):
	# class B inheriting property of class A
	# more properties of class B

Class C(B):
	# class C inheriting property of class A
	# class C also inherits properties of class B
	# more properties of class C