Using the "everything else" notations of * and **

Python offers even more flexibility in how we can define positional and keyword parameters for a function. The examples we've seen are all limited to a fixed and finite collection of argument values. Python allows us to write functions that have an essentially unlimited number of positional as well as keyword argument values.

Python will create a tuple of all unmatched positional parameters. It will also create a dictionary of all unmatched keyword parameters. This allows us to write functions that can be used like this:

>>> prod2(1, 2, 3, 4)

This function accepts an arbitrary number of positional arguments. Compare this with the prod() function shown previously. Our previous example required a ...

Get Python Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.