relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

Chris Angelico rosuav at
Mon Aug 22 01:41:43 CEST 2011

2011/8/22 Andreas Löscher <andreas.loescher at>:
> But every improvement on your algorithm will easily result in a
> significant shorter execution time than replaceing a+=1 with a=a+1 will
> ever do. :-)

Agreed. If Python needed a faster alternative to "a=a+1", then I would
recommend an "" call or something; some way to avoid looking up
the value of 1. (An equivalent to C's ++a operation, if you like.) But
I think you'd be hard-pressed to find any situation where improving
the speed of incrementing will be significant, that wouldn't be better
served by algorithmic improvements (even just using "for a in
range()") or dropping to C.


More information about the Python-list mailing list