function in python

>>> 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:

  *argsIt is a variable parameter, args a tuple is received;

  **kwKeyword 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 *argsIncoming: func(*(1, 2, 3));

  Keyword parameters can be passed directly: func(a=1, b=2), but also to assemble dict, and then by **kwpassing:func(**{'a': 1, 'b': 2})

Guess you like

Origin www.cnblogs.com/gaoyuxia/p/11098637.html