Message218338
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] |
|
Date |
User |
Action |
Args |
2014-05-12 16:58:01 | Kluzniak | set | recipients:
+ Kluzniak, docs@python |
2014-05-12 16:58:01 | Kluzniak | set | messageid: <1399913881.84.0.586979222354.issue21484@psf.upfronthosting.co.za> |
2014-05-12 16:58:01 | Kluzniak | link | issue21484 messages |
2014-05-12 16:58:01 | Kluzniak | create | |
|