function in the definition, by the parameter before the asterisking number, passing in a number of arguments into an object, a tuple or a dictionary, it can be said that these parameter values are collected.
Parameter with an asterisk indicates that all values are placed in the same tuple, and the return value of the parameter is a tuple.
The parameter is added with two asterisks to indicate that all values are placed in the same dictionary, and the return value of the parameter is a dictionary.
>>> def print_param (x, y, z = 3, *pospar, **keypar): print x, y, z print pospar print Keypar >& Gt;> Print_param (3,4,5,6,7,8,m = 1,n = 2) 3 4 5 (6, 7, 8) {' m ': 1, ' n ': 2}
Assigning parameters
function in the call, by the parameter before the asterisking number, the passed parameter must be a tuple or dictionary, the ability to convert its value to the value of the corresponding variable, this process can be considered as the allocation of parameter values.
An asterisk is added to the parameter to indicate that the tuple value is assigned to the corresponding function parameter value.
The parameter is added with two asterisks to indicate that the value in the dictionary is assigned to the key, and the key is used as the parameter name in the definition of the function.
>>> def add (x, y): print x, y return x + y >>> Add (*param) 1% >>> def test ( Name,age): print name,age >>> m = {' name ': ' Xiaoli ', ' age ': '}>>> test ' (**m) Xiaoli 12> >> m = {' name ': ' Xiaoli ', ' Age ':12}>>> test (**m) Xiaoli 12