Augmented assignment

Terry Reedy tjreedy at udel.edu
Tue Feb 21 01:46:15 EST 2006


"Suresh Jeevanandam" <jm.suresh at gmail.com> wrote in message 
news:dte88n$568$2 at home.itg.ti.com...
> Hi,
> Is there any gain in performance because of augmented assignments.
>
> x += 1  vs x = x+1
>
> Or are both of them the same.

The main gain is in programmer performance for writing a long name such as 
number_of_items once instead of twice.  Also in reading to see that the 
same name gets rebound to the new name.

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.

Terry Jan Reedy






More information about the Python-list mailing list