|
|
@ -8,6 +8,11 @@ def add(*args):
|
|
|
|
add(1, 2, 3, 4, 5)
|
|
|
|
add(1, 2, 3, 4, 5)
|
|
|
|
# 15
|
|
|
|
# 15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# You can also use the '*' operator to 'explode' a list of arguments
|
|
|
|
|
|
|
|
numbers = [1, 2, 3, 4, 5]
|
|
|
|
|
|
|
|
add(*numbers) # unpacks the list into an argument list for the function
|
|
|
|
|
|
|
|
# 15
|
|
|
|
|
|
|
|
|
|
|
|
# Now we have args (one '*') and kwargs (two '*'s)
|
|
|
|
# Now we have args (one '*') and kwargs (two '*'s)
|
|
|
|
# args is a tuple just like before, kwargs is a dictionary of the provided
|
|
|
|
# args is a tuple just like before, kwargs is a dictionary of the provided
|
|
|
|
# keyword arguments
|
|
|
|
# keyword arguments
|
|
|
|