Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04e7e0c

Browse files
committed
Close bug 417930 by clarifying augmented assignment docs
1 parent 8345f71 commit 04e7e0c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Doc/ref/ref6.tex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,20 @@ \subsection{Augmented assignment statements \label{augassign}}
300300
possible \emph{in-place} behavior, the binary operation performed by
301301
augmented assignment is the same as the normal binary operations.
302302

303+
For targets which are attribute references, the initial value is
304+
retrieved with a \method{getattr()} and the result is assigned with a
305+
\method{setattr()}. Notice that the two methods do not necessarily
306+
refer to the same variable. When \method{getattr()} refers to a class
307+
variable, \method{setattr()} still writes to an instance variable.
308+
For example:
309+
310+
\begin{verbatim}
311+
class A:
312+
x = 3 # class variable
313+
a = A()
314+
a.x += 1 # writes a.x as 4 leaving A.x as 3
315+
\end{verbatim}
316+
303317

304318
\section{The \keyword{pass} statement \label{pass}}
305319
\stindex{pass}

0 commit comments

Comments
 (0)