>>> def person(name,age,**kw):
... print('name:',name,'age:',age,'other:',*kw)
The variable parameter definition:
When defining the function parameter is defined as a variable parameter [in fact, it is in front of the variable parameters plus a number] *
To note defines the syntax of variable parameters and keyword parameters:
*args
It is a variable parameter, args a tuple is received;
**kw
Keyword parameters, kw received a dict.
How to pass variable parameters and syntax of the function is called keyword arguments:
Variable parameters can be passed directly: func(1, 2, 3)
, but also to the assembly list or tuple, and through *args
Incoming: func(*(1, 2, 3))
;
Keyword parameters can be passed directly: func(a=1, b=2)
, but also to assemble dict, and then by **kw
passing:func(**{'a': 1, 'b': 2})