Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00006a9

Browse files
author
Kenneth Reitz
committed
Merge pull requestrealpython#267 from simon-weber/binding-clarification
Clarify "late binding" in gotchas
2 parentsc7f1da2 +e1b5968 commit00006a9

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 bythen the loop has
136+
is looked up in the surrounding scope at call time. Bythen, 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)

[8]ページ先頭

©2009-2025 Movatter.jp