Python BASICS (2) -- functions, python basics -- Functions
Return Value:
All python functions have return values, but no return in the function body. The default return value is None,
Function parameters:
1. Common Parameters
In strict order, the actual parameters are assigned to the formal parameters, which correspond to each other.
Example:
def send(xxx,z,content):
print(xxx,z,content)
send("yy","dd",'niubi')
2. Default Parameters
It must be placed at the end of the parameter list, and the actual parameters can be set to default and overwrite.
Example:
Def send (xxx, z, content = 123 ):
Print (xxx, z, content)
Send ("yy", "dd", 'niubi ')
Running result:
Yy dd niubi
3. Specify parameters
The actual parameters are assigned to the specified formal parameters.
Example:
Def send (xxx, z, content = 123 ):
Print (xxx, z, content)
Send (z = "yy", xxx = "dd ")
Running result:
Dd yy 123.
4. One form parameter accepts multiple real parameters.
Add the * sign before the parameter, and the running result is the ancestor.
Example 1
Def send (* arg ):
Print (arg)
Send ([1, 2, 'ha ', 78])
Running result:
([1, 2, 'ha ', 78],)
Example 2
Def send (* arg ):
Print (arg)
Send ([1, 2, 'ha', 78], "nima", ("yoxi", 54 ))
Running result:
([1, 2, 'ha', 78], 'nim', ('yoxi', 54 ))
Add * before the formal parameter and actual parameter to extract the elements in the sequence and put them in the result ancestor. Note: No matter whether it is a form parameter or a real parameter, only one parameter can be included *.
Example 1
Def send (* arg ):
Print (arg)
A = [1, 2, 'ha ', 78]
Send (*)
Running result:
(1, 2, 'ha', 78)