I. Function classification
1. Built-in functions
2. Custom Functions
Two. Use of functions
1. Define First
(1) the process of preparing tool tools is called defining functions, and the built-in function interpreter is already defined and can be used Directly.
Example: def function name (test1,test2,test3):
function body
return value
There can be more than one return inside a function, but only to a return to end the call, return value as the Function's execution result returned, return value no type limit, no value, return None.
(2) the definition phase only detects syntax and does not execute Code.
(3) three types of function definitions:
No parameter function: just perform some operations, such as printing, user interaction
Parameter function: the corresponding logic needs to be executed according to the external parameters, such as statistical length, maximum number, etc.
Cases:
Empty function: Design Code structure
2. After use
Call the function procedure:
1. Find First Name
2. Call by name
Three types of function calls:
(1). Statement form: Test ()
(2). expression form: 2*len (' China ')
(3). arguments that can be used as another function
Three. parameters of the Function:
1. definition
parameter is variable name, argument is variable value
2. Specific applications
Positional parameters: parameters defined in order from left to right, with positional and positional arguments
Positional parameters: required parameter
Positional arguments: passing values to parameters by location
Keyword parameters: defined in key=value form
Note for keyword Parameters:
(1). The keyword argument must be behind the position parameter
(2). cannot repeat values for the same parameter
Default parameters: that is, the default parameter, that is, in the definition phase is already a parameter value, in the call stage can not pass Value.
Default parameter Considerations:
(1). The default parameter must be placed after the position parameter
(2). The default parameter is assigned only once, only once, in the definition Phase.
(3). The default parameter is best defined as an immutable type, string, or Number. (can type may change external values)
Variable long arguments: number of arguments
Processing mechanism: positional arguments are processed by *, and key arguments are handled by * *.
* Processing Example (the result is a tuple):
* * Processing Example (results received are dictionaries):
Python path-functions