1. Default value parameter
That is, the default value is set for the function parameter, when the function is called, the default value parameter is not passed, the defaults are invoked automatically, and the replaced argument is used if the parameter values for the default value are set.
You can use ' function name. Func_defaults ' (use ' function name. __defaults__ ' in Python3) to view the current values of all default value parameters for a function. The return value is a tuple that sequentially sorts the default values.
When you define a function with a default value parameter, the default value parameter must appear at the very right end of the function parameter list.
2. Key parameters
The arguments used when calling are not affected by the order.
3. Variable length parameters
*x is used to receive any number of arguments and place them in a tuple, **x to receive multiple arguments in a dictionary.
>>> def f (*x):
Print X
>>> F (1,2,3)
(1, 2, 3)
>>> def H (**x):
For I in X.items ():
Print I
>>> h (x = 1,y = 2,z = 3)
(' Y ', 2)
(' x ', 1)
(' Z ', 3)
>>> def H (**x):
Print X
>>> h (x = 1,y = 2)
{' Y ': 2, ' X ': 1}
>>> def H (**x):
Print X.keys ()
>>> h (x = 1,y = 2,z = 3)
[' Y ', ' x ', ' Z ']
>>> def H (**x):
Print x.values ()
>>> h (x = 1,y = 2,z = 3)
[2, 1, 3]
4. Sequence solution of parameter transfer
When passing arguments to functions that contain multiple variables, you can use lists, tuples, dictionaries, collections, and other iterated objects as arguments, and a *,python interpreter in front of the argument name is automatically decompressed and passed to multiple variables. If you use a dictionary as an argument, the default is a key, and the key value pair uses the items method, the value values method.
>>> def f (a,b,c):
Print A+b+c
>>> s = [1,2,3]
>>> F (*s)
6
>>> t = (1,2,3)
>>> F (*t)
6
>>> d = {1: ' A ', 2: ' B '}
>>> d = {1: ' A ', 2: ' B ', 3: ' C '}
>>> F (*d)
6
>>> s = {1,2,3}
>>> F (*s)
6
5.return
There is no return value returned statement that returns none.