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.

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))
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))
Output:
15
65
Explanation:
- *args allows passing a variable number of arguments.
- The sum() function is used to add all arguments.



