Skip to content

Commit 00006a9

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#267 from simon-weber/binding-clarification
Clarify "late binding" in gotchas
2 parents c7f1da2 + e1b5968 commit 00006a9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/writing/gotchas.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ What Does Happen
128128

129129
Five functions are created, but all of them just multiply ``x`` by 4.
130130

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.
133134

134135
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
136137
completed and ``i`` is left with its final value of 4.
137138

138139
What's particularly nasty about this gotcha is the seemingly prevalent

0 commit comments

Comments
 (0)