By using the same syntax when applying the args
sequence:
temp = function(*args)
The *args
syntax here is closely related to the *args
function parameter syntax; instead of capturing an arbitrary number of arguments, using *args
in a call expands the sequence to separate arguments.
You may be interested to know that there is a **kwargs
syntax too, to capture and apply keyword arguments:
def iterator(iterations, function, *args, **kwargs):
for i in range(iteration):
temp = function(*args, **kwargs)
return temp