mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Close bug 417930 by clarifying augmented assignment docs
This commit is contained in:
parent
8345f719c8
commit
04e7e0c60f
1 changed files with 14 additions and 0 deletions
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue