Loading search index…
No recent searches
No results for "Query here"
Here's a function that will take an arbitrary number of `int`s as arguments. ```python def sum(*nums): print(nums, " ") total = 0 for num in nums: total += num print(total) def main(): sum(1, 2) sum(1, 2, 3) nums = [1, 2, 3, 4] sum(*nums) if __name__ == "__main__": main()
We can run the Python script using:
$ python variadic-functions.py (1, 2) 3 (1, 2, 3) 6 (1, 2, 3, 4) 10
Another key aspect of functions in Python is their ability to form closures, which we’ll look at next.