Nine, function - parameters

Positional parameters

Positional parameters must be passed parameters, location parameters must be one to one, the number must be more, no less! ! !

 

The default parameters

It refers to the default parameters, a function definition, the parameter to a default value. The default parameters must be in the position parameter behind Oh.

 

Dynamic parameters

Refers to dynamic parameters, the dynamic parameters are passed, it can be any number of incoming values.

Dynamic parameters must be placed behind all positional parameters and default parameters.

Python dynamic parameters are: * args and ** kwargs.

1、*args

  A representative of asterisk to accept any number of parameters. When called, the arguments will be packaged as a parameter of the incoming tuple. If the argument is a list, the entire list will as a parameter.

  If the data in the list as a parameter passed in one wants, at the time of passing arguments, adding an asterisk in the preceding list. Any sequence type data objects (such as: a string, a tuple), can pass parameters to individually as a function this way. The dictionary, it will be passed one by one all the key.

 

 2 ** kwargs

  Two stars acceptance dynamic parameter key-value pairs, any number. Time of the call will be packaged into arguments dictionary. Contact an asterisk situation inside the two asterisks can pass one by one and key-value pair dictionary ** kwargs

 

The figure below shows key parameters using the format:

 

 

 

 

Guess you like

Origin www.cnblogs.com/KeenaCherry/p/11968275.html