Positional parameters, default parameters, variable parameters, named keyword parameters, keyword parameters
When used in combination, the definition of a parameter needs to be defined in turn in the direction described above.
The variable parameter actually receives a tuple, and the keyword parameter actually receives a dict.
Define the variable parameters with *, and define the keyword parameters with * *.
The named keyword parameter needs to be separated by the delimiter *, and the following parameter is the named keyword parameter. If you have previously defined a variable parameter, you do not need a separator *
Python's functions have a very flexible parameter shape that enables both simple calls and very complex parameters.
The default parameter must be an immutable object, and if it is a mutable object, the program will run with a logical error.
Note The syntax for defining variable parameters and keyword parameters:
*args is a variable parameter, args receives a tuple;
**KW is the keyword parameter, and kw receives a dict.
And how to pass the syntax of a variable parameter and keyword parameter when calling a function:
Variable parameters can be directly passed in: Func (1, 2, 3), can be assembled first list or tuple, and then passed through the *args: Func (* (1, 2, 3));
Keyword parameters can be passed directly into: Func (A=1, b=2), can be assembled dict first, and then passed **kw to: func (**{' a ': 1, ' B ': 2}).
Using *args and **kw is a Python idiom, and of course you can use other parameter names, but it's best to use idiomatic usage.
Named keyword parameters are designed to limit the number of parameter names that callers can pass in, and can provide default values.
Define a named keyword parameter do not forget to write the separator when there is no variable parameter, otherwise the location parameter will be defined.