I know that when we use *args
, it means we are not sure how many arguments the function is going to receive. However, Python finally binds them together in a single tuple:
>>> def f(*args):
return type(args)
>>> f(3,4,4,5)
<class 'tuple'>
Suppose I have a simple function that returns the input unchanged. I can use it with a nested lambda like this:
>>> def f (x):
return x
>>> l = f(lambda x: len(x))
>>>
>>> l((1,2,3))
3
Note that the input is a tuple. However, this is what happens when I try to write the same function with args
:
>>> def f (*args):
return args
>>> l = f(lambda x: len(x))
>>> l((1,2,3))
Traceback (most recent call last):
File "<pyshell#106>", line 1, in <module>
l((1,2,3))
TypeError: 'tuple' object is not callable
Why do I receive this error and how should I avoid it?