Tuples and immutability

Ethan Furman ethan at stoneleaf.us
Wed Mar 12 07:32:53 CET 2014


On 03/11/2014 08:25 PM, Terry Reedy wrote:
> On 3/11/2014 10:01 PM, Rick Johnson wrote:
>>
>> On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote:
>>> x += y is meant to be equivalent, except possibly in-place and
>>> more efficient, than x = x + y.
>
> The manual actually says "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a
> similar, but not exactly equal effect. In the augmented version, x is only evaluated once. 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.

... and reassigned to the target.  :)  (If it doesn't say that last part, it should.)

--
~Ethan~



More information about the Python-list mailing list