[docs] [issue21484] More clarity needed about difference between "x += e" and "x = x + e"

Feliks report at bugs.python.org
Mon May 12 18:58:01 CEST 2014


New submission from Feliks:

In Sec. 7.2.1 of the Language Reference, in the description of "+=" we have: "Also, when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead."
Although this is quite accurate, not all the consequences are immediately obvious, and sometimes they are quite serious.  I would suggest adding a note that points the reader's attention in particular to the phenomenon exhibited in the following example:
>>> def f(ls):  ls += [2]
... 
>>> def g(ls):  ls = ls + [2]
... 
>>> a = [1]
>>> g(a)
>>> a
[1]
>>> f(a)
>>> a
[1, 2]

----------
assignee: docs at python
components: Documentation
messages: 218338
nosy: Kluzniak, docs at python
priority: normal
severity: normal
status: open
title: More clarity needed about difference between "x += e" and "x = x + e"
type: enhancement
versions: Python 3.4

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


More information about the docs mailing list