multi-type pass-through values (passing tuples and dictionaries to functions)1 passing tuples to a function
def func (x, y ): Print X+y
When we call this function, we only need to pass in two variables, but for example I have a tuple T = (), I want to pass the value of T to Func, then Func (t) is not possible, because by default it takes T as 1 variables, then in this case, we need to use * T to indicate that the data in the memory address of T is passed in, then it can be. However, it is important to note that the number of elements in the tuple T is less than the number of parameters defined in the function, when the function requires 3 parameters, there are only two elements in T, then the pass is OK, but to manually specify a parameter can be called normally:
def func (x, Y, z): print x+y+= () func (1,*t)
This can be passed, and the *t of this notation, can only be placed on the far right (after the name of the parameter). you can also directly func (* ()) to pass the value2 Passing a dictionary to a functionIf you pass a dictionary, you need the following format
DIC = {'x': 2,'y': 3,'z': Ten} Func (**dic)
that's all you can do. But the key to the dictionary must be the same as the formal parameter of the function 3 Redundant parametersHandling redundant parameters (receiving redundant parameters)
def func (X,*args,**kwargs):
defined x named parameters, and two multi-type parameters, as redundant parametersby default, at least one named parameter is passed, and if there are many arguments, it is stored in args (in the form of a tuple), if the dictionary is passed, or the default (example X=1) value of the variable (in the form of a dictionary )
def func (x,*args,**Kwargs): print x print args print c8> Kwargsfunc (1,2,a=123)1(2,) {'a': 123 }
Python's multi-type pass-through and redundancy parameters