** indicates the meaning of python

** indicates the meaning of python

When the power supply operation and passing parameters defining parameters in python ** represents (a so-called parameter is passed in the function call parameters, parameter is a parameter defined function when a defined function), may also be used two special syntax: "` `* **. "

*** Use the function is called

test (* args) * actually function in each sequence args flying whale network element passed as positional parameters. For example, if the args equal to (1,2,3), then this code is identical to test (1,2,3).

test (** kwargs) ** function is to convert the dictionary kwargs as keyword arguments. For example, if kwargs equal to a ': 1,' b ': 2,' c ': 3, then this code is identical to the test (a = 1, b = 2, c = 3).

*** when using a custom function parameters

DEF test (* args):

... When you define a function parameter * different meanings, * args means that all incoming positional parameters are included in the tuple args. For example, if the call Test (1,2,3) In the above function, the value is args (1,2,3). :

DEF test (** kwargs):

... Similarly, ** and keyword arguments for dictionary. Call test (a = 1, b = 2, c = 3), kwargs value a ': 1,' b ': 2,' c ': 3.

Common definitions and parameters passed and * can coexist peacefully, but apparently * must be placed at the end of all positional parameters, * must be placed at the end of all keyword arguments, or will cause ambiguity.

Guess you like

Origin www.cnblogs.com/blogst/p/10965722.html