September 2026
1051 pages
35h 4m
English
In this section, you’ll learn another way of passing parameters to a function. To do this, suppose you want to determine the sum of all entries in a tuple using the extended version of the my_sum function defined in Section 17.6. This currently requires the following notation:
>>> t = (1, 4, 3, 7, 9, 2)>>> my_sum(t[0], t[1], t[2], t[3], t[4], t[5])26
This is very cumbersome. Furthermore, it runs counter to the general nature of the my_sum function, because the number of elements of the t tuple must always be known. It would thus be much better to have a way of passing a list of arguments stored in an iterable object directly to a function. This process is called unpacking, and it works similarly to ...
Read now
Unlock full access