python learning thirteenth day

Closure decorator
a closure (closure) is an important function of the syntax of programming. Closures also a tissue structure of the code, it also improves the reusability of code.
If an inline function, the variables in the outer function (but not in the global scope) is referenced, the inline function is considered to be closure (closure).
Defined within the external functions but the internal function or variable references by the use of free variables called
2 decorators understand example: everyone has panties main function is to modesty, but in the winter it is impossible for us to keep out the cold wind, supposed ? After one way we can think of is to look at the transformation of underwear, make it thicker longer, this way, it is not only modesty, but also provide warmth, but there is a problem, this is our underwear transformed into trousers Although there are functions modesty, but in essence it is no longer a real underwear. So smart people invented trousers, without the influence of underwear, trousers set directly on the outside underwear, so underwear or underwear, trousers with the baby no longer cold. Decorators as we say here trousers, without affecting the role of underwear, to our body provides a warm effect.
3 decorator is actually in order to add functionality to a program, but the program has been online or has been used, you can not modify the source code in large quantities, this is unscientific and unrealistic, because it had

: Decorator so that it satisfies
not modify the source code decorative function
can not be modified to be decorated is called a function
to add functionality to the program satisfying the conditions 1 and 2

Published 13 original articles · won praise 0 · Views 278

Guess you like

Origin blog.csdn.net/weixin_46269994/article/details/104468338