python for loop

Lada Kugis lada.kugis at gmail.com
Wed Apr 1 02:24:45 CEST 2009


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

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