python for loop

Lada Kugis lada.kugis at gmail.com
Tue Mar 31 20:44:26 EDT 2009


On Wed, 01 Apr 2009 02:24:45 +0200, Lada Kugis <lada.kugis at gmail.com>
wrote:

>I'm coming from fortran and c background so I'm certainly biased by
>them. But if you could explain one thing to me:
>
>in fortran for example:
>for i=1,n
>goes from 1,2,3,4,...,n

And of course, lapsus calami, this is wrong and it should go like:

do 1 i=1,n
... goes from ...

>
>in python for example:
>for i in range(1,n)
>goes from 1,2,3,4,...,n-1
>(that is, it goes from 1 up to, but not including n)
>
>Why is that so ? What were the reasons for that "not including" part ?
>It troubles me greatly, and I cannot see it's advantages over the
>"standard" "up to and including" n.
>
>Best regards
>Lada



More information about the Python-list mailing list