You use it when you want a program to be able to take any number of parameters, either positional (using *) or keywords (using **).
Here is an example using positional parameters. The function 'average' returns the average of all the parameters
You use it when you want a program to be able to take any number of parameters, either positional (using *) or keywords (using **).
Here is an example using positional parameters. The function 'average' returns the average of all the parameters.
You can also use * and ** when calling functions. This converts a sequence (*) or dictionary (**) into positional and keyword parameters respectively.
>>> def average(*params):
... return sum(params)/ float(len(params))
Dave - The Developers' Coach
>>> x = [1,2,3,4,25,100]
>>> average( *x )