c9

Chapter 9 of How to Think Like a Computer Scientist: Learning with Python 3, has just one little exercise at the end that requires writing code:

We’ve said nothing in this chapter about whether you can pass tuples as arguments to a function. Construct a small Python example to test whether this is possible, and write up your findings.

Here's a simple example:

def tupleply(tuple):
    """Multiply the elements of a tuple."""
    return tuple[0] * tuple[1]

sample_tuple = (2, 5)
print(tupleply(sample_tuple))

Sure enough, you can pass a tuple as an argument to a function.


This page is released under the GNU Free Documentation License, any version 1.3 or later produced by the Free Software Foundation. I am grateful to the authors of the original textbook for releasing it that way: Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers.