What is method overloading in Python?


Methods in Python can be called with zero, one, or more parameters. This process of calling the same method in different ways is called method overloading. It is one of the important concepts in OOP. Two methods cannot have the same name in Python; hence method overloading is a feature that allows the same operator to have different meanings.

Overloading is a method or operator that can do different functionalities with the same name.

#Program to illustrate method overloading
class edpresso:
def Hello(self, name=None):
if name is not None:
print('Hello ' + name)
else:
print('Hello ')
# Create an instance
obj = edpresso()
# Call the method
obj.Hello()
# Call the method with a parameter
obj.Hello('Kadambini')

In the code above, we are able to call the method Hello in two different ways with the help of method overloading.

Advantages of method overloading in Python

advantages
advantages

Method overloading…

  • reduces complexities
  • improves the quality of the code
  • is also used for reusability and easy accessibility

Thanks for reading!

Happy Coding.