Unlike other languages, functions can also be invoked as arguments (called "Top Citizens" in the book) .
Match parameter Collection keyword more laughed at!
- Functions can also be defined inside a function
- An intrinsic function can be considered as a closure (a closure is a function that can be dynamically generated by another function, and can be changed and stored outside the value of a variable created by the function)???
- Anonymous Harvey Lambda (), used instead of small functions, define the callback function???
Generator
This is definitely a super-good thing. Python has some of its own generator functions, such as range ()
You can also define your own generator function, where its return statement is completed by yield.
Decorative Device
Essence: Takes a function as input and returns another function.
Without affecting the source code, you can add some desired output. Common: Increase the basis of debug declarations to view incoming parameters
Such as: You can write a piece of code, the output source code contains functions, function parameters, as well as parameter invocation process, output and other information.
Usually use Python tips:
- *args, **kwargs
- Closed Package
- function as a parameter
Alternatively, you can add the adorner name directly before the function to be decorated @decorator_name:
The same function can be performed by more than one adorner, the adorner near the function definition Def, and then up. But any order will be the same result. (Adorners will never change the original code.)
Python function Learning