Functions can be broken down into built-in functions and custom functions. The main focus of this time is the custom function. Once the function is defined, it can be called wherever it is needed.
1 Importance of the return value
3 cases of Return value
No return value----return None
Indefinite return
Write only return: End a function
Return None----not used
Only one return value
Can return any data type
You can receive it as soon as you return.
If there is more than one return in a function, only the first one is executed
Return multiple values
Receive with multiple variables: How many variables are received with the number of return values
Receive with a variable: get a tuple
2 parameters
Formal parameters:
Actual parameters:
No parameters
No content is written in parentheses when defining functions and calling functions
has one parameter
Pass what is what
has multiple parameters
Position parameters
At the angle of the argument:
Pass the parameter by location
Follow the key word parameters
Mixing is possible, but you must first pass the parameter according to the location, and then follow the keyword; you cannot pass multiple values to the same variable
Standing on the angle of the formal parameter:
Positional parameters: Must pass, and have several parameters to pass several values
Default parameters: Can not pass, if not pass the default parameters, pass the Pass
Only when the function is called:
Pass by location: The value of the direct write parameter
by keyword: keyword = value
When defining a function:
Positional parameters: Defining parameters directly
Default parameter, keyword argument: parameter name = ' Default value '
Dynamic parameters: Can accept any number of parameters
Before the parameter name plus *, used to use *args (received by the value of the location parameter, organized into a tuple)
Before the parameter name plus * *, used to use **kwargs (received by the key to the value of the parameter, organized into a dictionary)
Order: Positional parameters, *args, default parameters, **kwargs
At the angle of the parameter, add a * to the variable, which is the combination of all the passed values.
At the angle of the argument, adding * to a sequence is to break the sequence in order
3 Comment of the function
def func ()
‘‘‘‘
what function does this function implement
Parameter 1: ...
Parameter 2: ...
Return: What is the returned thing
‘‘‘
Python Learning path Basic Article--09python Foundation, Primary knowledge function