if a write a function
def add(a,b):
return a+b
here, add will different results for add(1,2) and add(‘A’,‘B’),
also how the len function in python returns the length of list or string,
aren’t this examples of overloading?
if a write a function
def add(a,b):
return a+b
here, add will different results for add(1,2) and add(‘A’,‘B’),
also how the len function in python returns the length of list or string,
aren’t this examples of overloading?
Hey @shubhrs25_01611cd3f0e6aa02, first of all you must know that there is no concept of overloading in python. Firstly, in python the arguments of functions don’t have any type. Second is whenever you add two objects using the +
operator, the first object’s __add__
method is called with the second object as argument. So in our case a+b will be equivalent to a.__add__(b)
of class a. This is how + operator works by default in python. Similarly, len function of the class of the argument is called. Hence there is nothing like method/function overloading in python.
I hope this clears your doubt !
Happy Learning !
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.