0

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?

smci
  • 29,564
  • 18
  • 109
  • 144
user4016367
  • 321
  • 7
  • 22
  • 2
    Python does not support overloading the way you are trying to use it. – khelwood Jan 29 '18 at 12:27
  • 1
    No it doesn't, and if you search, this has been answered many times before. – Carcigenicate Jan 29 '18 at 12:28
  • 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 – smci Feb 19 '18 at 08:45

0 Answers0