The function is to combine a bunch of statements together to form a part:
1. Maximum code reuse, minimal code redundancy
2. Process decomposition, function is about the process, tell you how to do things
Parameter description for function passing
The red section is especially careful, otherwise there will be syntax errors, and another is that if given the default value of the parameter, it must be placed in the absence of the default value of the argument, put in front of the same syntax error,
* Star args returns the tuple tuple meta-progenitor star args Returns a dictionary
python defaults to matching variable names from left to right , and for arguments, underlining is the best way to learn
Country not given is the default CN
...
def f (a,b,c)
Prin (A,B,C)
F (a)
Output: 1 2 3
...
keyword Parameters , position-based parameters are first matched from left to right, followed by keyword matching, that is, if a keyword is used to pass a parameter, the parameter is passed through the variable name and is no longer a position.
...
F (1,b=3,c=2)
1 3 2
...
The default parameter is to invoke the function without passing the default value, pass the value of the pass
...
def f (a,b=2,c=3):
Print (A,B,C)
F (1)
F (+)
F (1,c=2,b=3) can be
...
keywords and default parameters mixing cases It's easy to see the excitement
any parameter with these two examples can be understood, a tuple, a dictionary
Finally this mix is also very good to use, draw a good line at a glance
Another knowledge point is the unpacking function, said the call function when the parameters passed with an asterisk, to be unpacked, solve the tuple, solve the dictionary.
python-Function-Parameters