Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Arbitrary number of arguments passing a lists

from mysum import mysum

x = [2, 3, 5, 6]

mysum(x)

Output:

([2, 3, 5, 6],)
<class 'tuple'>
Traceback (most recent call last):
  File "/home/gabor/work/slides/python/examples/functions/sum_of_list.py", line 5, in <module>
    mysum(x)
  File "/home/gabor/work/slides/python/examples/functions/mysum.py", line 6, in mysum
    total += s
TypeError: unsupported operand type(s) for +=: 'int' and 'list'
from mysum import mysum

x = [2, 3, 5, 6]

print(mysum(*x))

Output:

(2, 3, 5, 6)
<class 'tuple'>
16