[issue21358] Augmented assignment doc: clarify 'only evaluated once'

Martin v. Löwis report at bugs.python.org
Sat Apr 26 23:03:57 CEST 2014


Martin v. Löwis added the comment:

This is not limited to dictionaries. Augmented assignment *always* involves a read operation and a write operation. 
So Antoine's remark in msg215573 is more general;

a.x += 1

has a get and a set, and even

x += 1

has a get and a set.

I still agree that the original statement is confusing. It (implicitly) claims that 

  x = x + 1

evaluates x twice, which it does not. Instead, x is only *evaluated* once, and then written to. Only if x has subexpressions, they get evaluated only once ("evaluation" being the thing that produces a "value").

----------
nosy: +loewis

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21358>
_______________________________________


More information about the Python-bugs-list mailing list