Table of contents
1.
Introduction
2.
Method Overloading
2.1.
Example of Method Overloading
3.
Method Overriding
3.1.
Example of Method Overriding
4.
Difference between Method Overloading and Method Overriding in Python
5.
Frequently Asked Questions
5.1.
Does Python support method overloading?
5.2.
How does method overriding work in Python?
5.3.
What is the key difference between overloading and overriding?
6.
Conclusion
Last Updated: Aug 7, 2025
Medium

What is Overloading And Overriding in Python?

Author Pallavi singh
0 upvote

Introduction

Overloading and overriding are key concepts in Python's object-oriented programming. Method overloading allows multiple methods with the same name but different parameters, though Python achieves this using default or variable-length arguments. Method overriding lets a subclass redefine a method from its superclass to change its behavior. 

What is Overloading And Overriding in Python?

In this article, you will learn the differences between overloading and overriding in Python with examples.

Method Overloading

Method overloading means defining multiple methods with the same name but different parameters. Python does not support method overloading like other programming languages (such as Java and C++), but we can achieve a similar effect using default arguments or the *args and **kwargs parameters.

Example of Method Overloading

Here is an example of method overloading using default arguments:

class Calculator:
    def add(self, a, b, c=0):
        return a + b + c

# Creating an object of Calculator class
calc = Calculator()

# Calling add method with two arguments
print(calc.add(5, 10))  

# Calling add method with three arguments
print(calc.add(5, 10, 20)) 
You can also try this code with Online Python Compiler
Run Code

 

Output: 

15
35

 

Explanation:

  • The add method takes three parameters, but the third parameter has a default value of 0.
     
  • If we pass two arguments, it sums only the first two values.
     
  • If we pass three arguments, it sums all three values.
     

Another way to implement method overloading is using *args:

class Calculator:
    def add(self, *args):
        return sum(args)

calc = Calculator()
print(calc.add(5, 10))  
print(calc.add(5, 10, 20, 30)) 
You can also try this code with Online Python Compiler
Run Code

 

Output: 

15
65

 

Explanation:

  • *args allows passing a variable number of arguments.
     
  • The sum() function is used to add all arguments.

Method Overriding

Method overriding occurs when a subclass provides a new implementation for a method that is already defined in its parent class. This is useful when a child class needs a behavior different from its parent class.

Example of Method Overriding

Let's see an example of method overriding:

class Animal:
    def make_sound(self):
        return "Some generic animal sound"

class Dog(Animal):
    def make_sound(self):
        return "Bark"

# Creating objects of Animal and Dog classes
animal = Animal()
dog = Dog()

print(animal.make_sound())  
print(dog.make_sound()) 
You can also try this code with Online Python Compiler
Run Code

 

Output: 

Some generic animal sound
Bark

 

Explanation:

  • The Animal class has a method make_sound().
     
  • The Dog class overrides this method to return "Bark" instead of the generic sound.
     
  • When calling make_sound() on an object of Dog, it executes the overridden method.
     

Another example using super() to call the parent class method:

class Animal:
    def make_sound(self):
        return "Some generic animal sound"

class Cat(Animal):
    def make_sound(self):
        return super().make_sound() + " but I prefer Meow"

cat = Cat()
print(cat.make_sound()) 
You can also try this code with Online Python Compiler
Run Code

 

Output: 

Some generic animal sound but I prefer Meow

 

Explanation:

  • super().make_sound() calls the parent class method first.
     
  • Then, additional behavior is added in the child class.

Difference between Method Overloading and Method Overriding in Python

FeatureMethod OverloadingMethod Overriding
DefinitionDefining multiple methods with the same name but different parametersRedefining a method in a child class that is already present in the parent class
ParametersDifferent parameter listsSame parameter list as the parent method
UsageAchieved using default arguments or *argsAchieved by defining the method in the subclass
FlexibilityProvides multiple ways to use a functionChanges the behavior of an inherited method
Python SupportNot directly supported, but can be mimickedFully supported

Frequently Asked Questions

Does Python support method overloading?

Python does not support traditional Method overloading like Java or C++, but we can achieve similar functionality using default arguments or *args.

How does method overriding work in Python?

Method overriding occurs when a subclass defines a method with the same name and parameters as the parent class, replacing the parent's implementation.

What is the key difference between overloading and overriding?

Overloading deals with multiple methods with the same name but different arguments, while overriding changes the behavior of an inherited method in a subclass.

Conclusion

In this article, we discussed overloading and overriding in Python. Method overloading allows defining multiple methods with the same name but different parameters, though Python achieves this using default arguments. Method overriding occurs when a subclass provides a specific implementation of a method defined in its superclass. Understanding these concepts helps in writing flexible and reusable object-oriented code in Python.

Live masterclass