This is a created article in which the information may have evolved or changed.
Basic Foundation Foundation Foundation BASE!!! , this is a repeated trampling of the pit, more than once ...
Let's take a first example:
Example 1
Very simple, after execution, print 1, 2, 3, 4, 5. Add anonymous function again
Example 2
Print the n value in the anonymous function, and then print 1, 2, 3, 4, 5. My use of the scene is very simple, advertising has a lot of filter plug-ins, many can be reused the same struct, just according to name to distinguish. Filter conditions to be registered in a global map for subsequent use, as in logic Example 3:
Example 3
The code logic is clear, after the execution of the discovery output is 5, 5, 5, 5, 5 ...
In fact, the principle is very simple, and Python is also very similar, the closure is lazy to generate FN when n is in the For loop outer layer, and so on the execution of FN when n has become 5. It is easy to fix, N to generate a temporary object copy n value in the form of a parameter to FN, or for a for loop.
Example 4