File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
Original file line number Diff line number Diff line change @@ -128,11 +128,12 @@ What Does Happen
128
128
129
129
Five functions are created, but all of them just multiply ``x `` by 4.
130
130
131
- Python's closures are *late binding *. This means that names within closures are
132
- looked up at the time the inner function is *called *.
131
+ Python's closures are *late binding *.
132
+ This means that the values of variables used in closures are looked
133
+ up at the time the inner function is called.
133
134
134
135
Here, whenever *any * of the returned functions are called, the value of ``i ``
135
- is looked up in the surrounding scope at call time, when by then the loop has
136
+ is looked up in the surrounding scope at call time. By then, the loop has
136
137
completed and ``i `` is left with its final value of 4.
137
138
138
139
What's particularly nasty about this gotcha is the seemingly prevalent
You can’t perform that action at this time.
0 commit comments