Inheritance in Python

Inheritance is the powerful property of object oriented programming through which the features of a class are derived into its sub class.

or we can Say “inheritance is the super class -sub class or parent class-child class relationship.

How inheritance is achieved in python.

Single Inheritance:

class A:
 def display(self):
  print("this is base class function")
class B(A): # how class is inherited
 def show(self):
  print("this is sub class function")
a1=A()
a1.display() # A clas object may call only A class functions.
b1=B()
b1.display() 
b1.show() # B class object may call B class as well as A class object.

    Output:
    this is base class function
    this is base class function
    this is sub class function

Multilevel inheritance in python:

class A:
 def test1(self):
  print("A class function")
class B(A):
 def test2(self):
  print("B class function")
class C(B): # multilevel inheritance
 def test3(self):
  print("C class function")
c1=C()
c1.test1() #c class object may also call A and B class functions.
c1.test2()
c1.test3()

    Output:
    A class function
    B class function
    C class function

Multiple inheritance in python:

class A:
 def test1(self):
  print("A class function")
class B(A):
 def test2(self):
  print("B class function")
class C(A,B): #C class inherites both A & B classes  def test3(self):   print("C class function") c1=C() c1.test1() #c class object may also call A and B class functions. c1.test2() c1.test3()

    Output:
    A class function
    B class function
    C class function

Click Here

Video/ C Introduction

Watch video in full size