Sitemap
Kavisha Nethmini

Kavisha Nethmini

Continuing My Python OOP Journey

2 min readJul 2, 2026

Understanding Inheritance in python

In my previous blog, I explored the fundamentals of Object-Oriented Programming (OOP) in Python, including classes, objects, constructors, instance methods, static methods, class methods, and getters & setters.

As I continued studying Python, I came across another important OOP concept called Inheritance. From that I understood how inheritance helps us write cleaner, reusable, and well-organized code.

What is Inheritance

Inheritance is an Object-Oriented Programming (OOP) concept that allows one class to inherit the attributes and methods of another class.

  • The existing class is called the Parent (Base) Class.
  • The new class is called the Child (Derived) Class.

The child class can use everything available in the parent class while also adding its own features.

Get Kavisha Nethmini’s stories in your inbox

Join Medium for free to get updates from this writer.

Single Inheritance

class Company:
def company_info(self):
print("Company Name is XYZ")


class Employee(Company):
def employee_info(self):
print("Employee Name is Rahul")


emp = Employee()

emp.company_info()
emp.employee_info()

Here one child class inherits from one parent class. Although company_info() is not defined inside Employee, it can still access the method because it inherits from the parent class.

Multiple Inheritance

class Company:

def __init__(self, company_name):
self.company_name = company_name

def company_info(self):
print(f"Company Name is {self.company_name}")


class Country:

def __init__(self, country_name):
self.country_name = country_name

def country_info(self):
print(f"Country Name is {self.country_name}")


class Employee(Company, Country):

def __init__(self, employee_name, company_name, country_name):
self.employee_name = employee_name

Company.__init__(self, company_name)
Country.__init__(self, country_name)

def full_info(self):
print(
f"The employee {self.employee_name} lives in {self.country_name} and works for {self.company_name}"
)


emp = Employee("Kavi", "XYZ", "USA")

emp.full_info()
emp.company_info()
emp.country_info()

In multiple inheritance allows child class to inherit from more than one parent class.

Multilevel Inheritance

class Company:

def __init__(self, company_name):
self.company_name = company_name

def company_info(self):
print(f"Company Name is {self.company_name}")


class Department(Company):

def __init__(self, department_name, company_name):
self.department_name = department_name
Company.__init__(self, company_name)

def department_info(self):
print(
f"The department is {self.department_name} of {self.company_name}"
)


class Employee(Department):

def __init__(self, employee_name, department_name, company_name):
self.employee_name = employee_name
Department.__init__(self, department_name, company_name)

def employee_info(self):
print(f"Employee Name is {self.employee_name}")


emp = Employee("Rahul", "HR", "ABC")

emp.employee_info()
emp.department_info()
emp.company_info()

Multilevel inheritance happens when a class inherits from another child class.

Inheritance is one of the core concepts of Object-Oriented Programming that makes Python more powerful and flexible. Whether it is Single Inheritance, Multiple Inheritance, or Multilevel Inheritance, each type helps us organize code and improve reusability.

--

--