python for loop

Steven D'Aprano steven at
Wed Apr 1 03:26:41 CEST 2009

On Wed, 01 Apr 2009 02:24:45 +0200, Lada Kugis 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
> 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.

Why Python (and other languages) count from zero instead of one, and 
why half-open intervals are better than closed intervals:


More information about the Python-list mailing list