I. Definition and invocation of Python functions
the definition of a function : (function) code block.
is to integrate the code we want to execute into a code block that can be called.
Functions are blocks of code that can be called repeatedly, with several advantages:
- Reduce Code Redundancy
- Code Structure Clear
- Helps keep your code consistent
Division of Functions
- Divide by parameter type
- Positional parameters: is the way that we pass the arguments in the order in which they are passed, as defined by the parameters
-
- Keyword parameter: It is when we pass the parameter, we ignore the order of the form parameter equal to the argument, and then we pass the parameter.
-
- Default parameter: When defining a parameter, a default value is given to the formal parameters. When a function is called, the default value is automatically applied if no parameter is passed to the default value. "NOTE: The default parameter must be written after the normal parameter"
- Divide by return value "difference is whether there is a return value"
- return type function "have"
- Computed type function "None"
Ii. Anonymous functions and maps
- Lambda anonymous functions are one of the functions in Python.
The difference: Def defines a function as a statement block, whereas a lambda function is an expression.
The DEF function has a function name, and the lambda function has no
The lambda function body can only be an expression, and the result is automatically fed back
- The map function executes in bulk: The following sequence is called sequentially as a parameter of the preceding function
Python function programming