Title here
Summary here
Variadic functions can be called with any number of trailing arguments. For example, print
is a common variadic function.
Here’s a function that will take an arbitrary number of integers as arguments.
Within the function, the type of nums
is equivalent to tuple
. We can call len(nums)
, iterate over it with a loop, etc.
Variadic functions can be called in the usual way with individual arguments.
If you already have multiple args in a list, you can apply them to a variadic function using func(*list)
like this:
The expected output when running this script will be:
Another key aspect of functions in Python is their ability to form closures, which we’ll look at next.