summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-03-06 07:22:09 (GMT)
committerGeorg Brandl <georg@python.org>2008-03-06 07:22:09 (GMT)
commit26bab5f92a9ec67647a1893dfc497d822c1f62bd (patch)
tree72a872c475dda791676898a99ea95a78de0603ad
parent70992c3c83e2324677ad4fee73f372682f036c18 (diff)
downloadcpython-26bab5f92a9ec67647a1893dfc497d822c1f62bd.zip
cpython-26bab5f92a9ec67647a1893dfc497d822c1f62bd.tar.gz
cpython-26bab5f92a9ec67647a1893dfc497d822c1f62bd.tar.bz2
Little clarification of assignments.
-rw-r--r--Doc/tutorial/classes.rst19
1 files changed, 11 insertions, 8 deletions
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index 7761095..2eb86e2 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -123,6 +123,8 @@ found outside of the innermost scope are read-only (an attempt to write to such
a variable will simply create a *new* local variable in the innermost scope,
leaving the identically named outer variable unchanged).
+.. XXX mention nonlocal
+
Usually, the local scope references the local names of the (textually) current
function. Outside functions, the local scope references the same namespace as
the global scope: the module's namespace. Class definitions place yet another
@@ -136,14 +138,15 @@ language definition is evolving towards static name resolution, at "compile"
time, so don't rely on dynamic name resolution! (In fact, local variables are
already determined statically.)
-A special quirk of Python is that assignments always go into the innermost
-scope. Assignments do not copy data --- they just bind names to objects. The
-same is true for deletions: the statement ``del x`` removes the binding of ``x``
-from the namespace referenced by the local scope. In fact, all operations that
-introduce new names use the local scope: in particular, import statements and
-function definitions bind the module or function name in the local scope. (The
-:keyword:`global` statement can be used to indicate that particular variables
-live in the global scope.)
+A special quirk of Python is that -- if no :keyword:`global` or
+:keyword:`nonlocal` statement is in effect -- assignments to names always go
+into the innermost scope. Assignments do not copy data --- they just bind names
+to objects. The same is true for deletions: the statement ``del x`` removes the
+binding of ``x`` from the namespace referenced by the local scope. In fact, all
+operations that introduce new names use the local scope: in particular, import
+statements and function definitions bind the module or function name in the
+local scope. (The :keyword:`global` statement can be used to indicate that
+particular variables live in the global scope.)
.. _tut-firstclasses: