17day
Function
1. Function definition:
A function is a collection of a set of statements encapsulated by a name (function name), to execute the function, simply call its name
2, the function of the characteristics:
A reduce duplicate code
b makes the program extensible
C makes the program easier to maintain
3, formal parameters, actual parameters
Parametric: Allocates a memory unit only when it is called, releasing the allocated memory unit immediately after the call is completed. Therefore, the formal parameter is only valid inside the function. After the function call finishes returning the calling function, you can no longer use the shape parametric
Arguments: Can be constants, variables, expressions, functions, and so on, regardless of the amount of the actual argument, they must have a definite value when making a function call to pass these values to the formal parameter. Therefore, an assignment, input, and so on should be used to obtain a definite value for the argument.
4. Default parameters
The default argument is written after the non-default parameter, which is not specified at the time of invocation, and is the default value. If specified, the specified value is used
5. Key parameters
Under normal circumstances, to pass parameters to the function in order (order parameters), do not want to be in order to use the key parameters, only need to specify the parameter name (parameter named parameter is called the key parameter)
Note: Key parameters must be placed after the position parameter
6, non-fixed parameters
Multiple parameters can be passed
Method One: To implement the non-fixed parameter *args in the way of tuples, if the parameter appears *, the parameters passed is no longer a fixed number, all the parameters transmitted to the tuple
Method Two: Realize the non-fixed parameter **kwargs in the way of the dictionary
Python Beginner 17th Day function (1)