INHERITANCE
In Python, inheritance is an Object-Oriented Programming (OOP) concept where one class (child/derived class) can reuse the properties and methods of another class (parent/base class).
Key Points About Inheritance
Code Reusability — You don’t have to rewrite the same code in multiple classes.
Parent Class (Base Class) — The class whose properties are inherited.
Child Class (Derived Class) — The class that inherits from another class.
Types of Inheritance in Python
| Type | Description |
| ---------------- | ------------------------------- |
| **Single** | One parent → one child |
| **Multiple** | Two or more parents → one child |
| **Multilevel** | Parent → Child → Grandchild |
| **Hierarchical** | One parent → multiple children |
| **Hybrid** | Combination of multiple types |
Hierarchical Inheritance
Definition:
In hierarchical inheritance, one parent class is inherited by multiple child classes.
Get Sowmithra’s stories in your inbox
Join Medium for free to get updates from this writer.
Your code structure:
In (parent class)
/ | \
Add Sub Multiplication (child classes)call here is just another name for self (you can name it anything).
class In:
def input(call):
call.a=int(input("Enter A value:"))
call.b=int(input("Enter B value:"))
class Addition(In):
def add(call):
call.input()
c=call.a + call.b
print("Addition:", c)
class Subtraction(In):
def sub(call):
call.input()
c = call.a - call.b
print("Subtraction:", c)
class multipilation(In):
def mul(call):
call.input()
c=call.a * call.b
print("Addition:", c)
obj1=Addition()
obj1.add()
obj2=Subtraction()
obj2.sub()
obj3=multipilation()
obj3.mul()Each child class object directly uses the parent class method via inheritance.
This is hierarchical inheritance — single parent → many children.
Hybrid Inheritance
Definition:
Hybrid inheritance is a combination of two or more types of inheritance (like multiple + hierarchical).
In (Parent)
/ \
Addition Subtraction
\ /
Arithmetic (inherits from both)
class In:
def input(call):
call.a=int(input("Enter A value:"))
call.b=int(input("Enter B value:"))
class Addition(In):
def add(call):
call.input()
c=call.a + call.b
print("Addition:", c)
class Subtraction(In):
def sub(call):
call.input()
c = call.a - call.b
print("Subtraction:", c)
class Arithmetic(Addition,Subtraction):
def arith(call):
call.add()
call.sub()
obj = Arithmetic()
obj.arith()




