1

Python doesn't seem to support function overloading:

>>> def overload(x,y):
...     return x*y
... 
>>> def overload(x,y,z):
...     return x*y*z
... 
>>> overload(1,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: overload() takes exactly 3 arguments (2 given)
>>> overload(1,2,3)
6
>>>

Is it just for a specific version of python or python never supports function overloading?

3
  • 2
    Python does not support overloading the way you are trying to use it. Commented Jan 29, 2018 at 12:27
  • 1
    No it doesn't, and if you search, this has been answered many times before. Commented Jan 29, 2018 at 12:28
  • 1
    It doesn't support overloading by allowing multiple signatures with different number of positional args. But you can get overloading by using keyword args where the optional extra args have defaults supplied: def overload(x,y,z=1): return x*y*z works for this case Commented Feb 19, 2018 at 8:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.