Python: Closures

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.

When an inline function as a reference variable outside its scope, we will get a closure to sum up, to create a closure must meet the following points:

There must be an inline function
inline function must reference an external variable in the function
return value of the external function must be built-in functions
feel closure or difficult, a few words she did not understand, or look up the relevant information.

Focus is on the function to run and will not be revoked, as instance of the same title dictionary 16, when the function finishes running, instance not be destroyed, but remain in the memory space. This feature is similar to the class of the class variables, but moved to the function.

Closures like a hollow sphere, like, you know, outside and inside, but you do not know what the middle.

Guess you like

Origin blog.csdn.net/weixin_44523387/article/details/91807077