Augmented assignment

Terry Reedy tjreedy at udel.edu
Tue Feb 21 11:48:05 EST 2006


<bonono at gmail.com> wrote in message 
news:1140506094.387829.60890 at g14g2000cwa.googlegroups.com...
>
> Terry Reedy wrote:
>> Program performance might be noticeable if 'x' is something like a.b.c.d
>> that takes some lookup time.  But again, I would use the += form for
>> readability without testing run time.
>
> Would x=x + 1 be more readable, regardless of the background(whether
> being introduced to the += form in some other language like C before) ?

To *me*,

able.baker.charles.delta += 1

is more easily read than

able.baker.charles.delta = able.baker.charles.delta +1

because it is clear that there is one and only one attribute involved, 
being updated in place, whereas the latter might have been

able.baker.charles.delta = able.baker.charley.delta +1

Therefore, as I said originally *I* would use the += form.

Terry Jan Reedy






More information about the Python-list mailing list