]> granicus.if.org Git - python/commitdiff
Close bug 417930 by clarifying augmented assignment docs
authorRaymond Hettinger <python@rcn.com>
Tue, 25 Jun 2002 13:36:41 +0000 (13:36 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 25 Jun 2002 13:36:41 +0000 (13:36 +0000)
Doc/ref/ref6.tex

index 12261e2f7bf1990b145dec49e2c5e38226bed26f..80fae5ab84398eca564dc4f36e1667550dd8e0e3 100644 (file)
@@ -300,6 +300,20 @@ the same way as normal assignments. Similarly, with the exception of the
 possible \emph{in-place} behavior, the binary operation performed by
 augmented assignment is the same as the normal binary operations.
 
+For targets which are attribute references, the initial value is
+retrieved with a \method{getattr()} and the result is assigned with a
+\method{setattr()}.  Notice that the two methods do not necessarily
+refer to the same variable.  When \method{getattr()} refers to a class
+variable, \method{setattr()} still writes to an instance variable.
+For example:
+
+\begin{verbatim}
+class A:
+    x = 3    # class variable
+a = A()
+a.x += 1     # writes a.x as 4 leaving A.x as 3
+\end{verbatim}
+
 
 \section{The \keyword{pass} statement \label{pass}}
 \stindex{pass}