Augmented assignment

Terry Hancock hancock at anansispaceworks.com
Tue Feb 21 14:20:56 EST 2006


On Tue, 21 Feb 2006 10:55:42 +0530
Suresh Jeevanandam <jm.suresh at gmail.com> wrote:
> 	Is there any gain in performance because of
> 	augmented assignments.
> 
> 	x += 1  vs x = x+1

Yep. I perform better when I only type names once.
Especially if they are long:

length_of_object_I_must_describe_very_carefully += 1

vs

length_of_object_I_must_describe_very_carefully = length_of_object_I_must_describe_very_carefully + 1

Oh, you mean performance of the computer? ;-)

But Python is all about optimizing the
performance of programmers, not computers!

Seriously,
I think they are usually equivalent internally,
at least for immutable objects.

-- 
Terry Hancock (hancock at AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com




More information about the Python-list mailing list