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 overloadingclass edpresso:def Hello(self, name=None):if name is not None:print('Hello ' + name)else:print('Hello ')# Create an instanceobj = edpresso()# Call the methodobj.Hello()# Call the method with a parameterobj.Hello('Kadambini')
In the code above, we are able to call the method Hello
in two different ways with the help of method overloading
.
Thanks for reading!
Happy Coding.