summing = lambda *x: sum(*x)
is basically the same as
def summing(*x): return sum(*x)
but functions are prefered, as they are more readable and a bit faster.
However, you shouldn't use either of the above code snippets. *x
allows for a variable amount of arguments, only to unpack them for sum()
.
If you want to pass your summing()
function arguments like this:
summing(1,2,3,4)
... use the following code:
def summing(*x): return sum(x)
If you want to give it a sequence instead...
summing([1,2,3,4])
... use this:
def summing(x): return sum(x)
Your variant...
def summing(*x): return sum(*x)
... requires a sequence to be passed (like the function above, hence you don't need *x
twice!), you can't give it (1,2,3,4)
. sum()
takes an iterable as first argument, the second is for a start value. sum(*x)
will throw errors at you.