Lower bounds of lists

jcm grumble at mailcity.com
Thu Mar 1 18:28:58 EST 2001


Michael Prager <Mike.Prager at noaa.gov> wrote:
> As a newcomer to Python, I'm curious about the choice to number
> list elements starting at zero, rather than one.  My impression
> is that there is no user option to change that in a specific
> program.  Correct?

> It seems an odd choice, as humans count from one, and Python in
> other respects seems quite logical and well thought out.
> Starting lists at zero also seems to have had ripple effects,
> such as 

> range(1,100) giving (1, 2, 3, ... , 99)

> which leads to such odd conscructions as 

> for i in range(start ,stop+1):
> 	#do something

> Though I don't consider quirks in computer software lovable, I'm
> convinced that Python's virtues far outweigh any inconvenience
> caused by this.  I am curious, though, how this choice came
> about.  Can anyone refer me to source material on that, or
> explain the logic behind it?

I like the idea of list indices beginning with 0, since the index can
then be thought of as an offset.  Not sure if this was the original
motivation though.

range's behavior is also nice, because

  range(a, b)

evaluates to the same thing as

  range(a, n) + range(n, b)

does.  No need for and +1 or -1 adjustments.
Assuming a <= n <= b of course.



More information about the Python-list mailing list