Coding style and Python versions (was Re: Another itertool function?)
Alex Martelli
aleax at aleax.it
Mon Apr 28 10:07:27 EDT 2003
Aahz wrote:
> In article <b8hc64$6n2$1 at slb9.atl.mindspring.net>,
> Andrew Dalke <adalke at mindspring.com> wrote:
>>
>> i = i + 1
>
> I'm a little curious why you didn't write this as
>
> i += 1
>
> Any reason (i.e. still need to support 1.5.2) or just habit? If the
> latter, why haven't you changed your habit?
There is no special reason to "change that habit", e.g. not performance:
[alex at lancelot src]$ python Lib/timeit.py 'i=0; i+=1'
1000000 loops, best of 3: 0.284 usec per loop
[alex at lancelot src]$ python Lib/timeit.py 'i=0; i=i+1'
1000000 loops, best of 3: 0.281 usec per loop
[alex at lancelot src]$ python Lib/timeit.py 'i=0; i=i+1'
1000000 loops, best of 3: 0.281 usec per loop
[alex at lancelot src]$ python Lib/timeit.py 'i=0; i=i+1'
1000000 loops, best of 3: 0.284 usec per loop
[alex at lancelot src]$ python Lib/timeit.py 'i=0; i+=1'
1000000 loops, best of 3: 0.282 usec per loop
[alex at lancelot src]$ python Lib/timeit.py 'i=0; i+=1'
1000000 loops, best of 3: 0.278 usec per loop
No statistically significant / measurable difference. The tiny difference
in conciseness is hardly compelling one way or another, either.
Alex
More information about the Python-list
mailing list