The method overriding in Python means creating two methods with the same name but differ in the programming logic. The concept of Method overriding allows us to change or override the Parent Class function in the Child Class.
In Python, to override a method, you have to meet certain conditions and they are:
In this article, we will show you, how to perform Method Overriding in Python Programming Language with an example.

Python Method Overriding with arguments
Until now, we are only changing the print statement. I mean, overriding methods without any arguments. In this example, we created an add method with two arguments in parent class and three arguments in child class.
class Employee:
def add(self, a, b):
print('The Sum of Two = ', a + b)
class Department(Employee):
def add(self, a, b, c):
print('The Sum of Three = ', a + b + c)
emp = Employee()
emp.add(10, 20)
print('------------')
dept = Department()
dept.add(50, 130, 90)OUTPUT

Calling Parent Function within the Method Overriding in Python
In this Python method overriding example, we are calling the parent function from the overriding method.
class Employee:
def message(self):
print('This message is from Employee Class')
class Department(Employee):
def message(self):
super().message()
print('This Department class is inherited from Employee')
emp = Employee()
emp.message()
print('------------')
dept = Department()
dept.message()OUTPUT

Thank You for Visiting Our Blog