Lower bounds of lists
chris.gonnerman at usa.net
Fri Mar 2 01:45:23 CET 2001
----- Original Message -----
From: "Michael Prager" <Mike.Prager at noaa.gov>
Subject: Lower bounds of lists
> 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.
Humans count from 1. Hackers count from 0.
> 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
Sometimes. If the values of i are not directly important (just the
number of iterations), I just use
for i in range(iterations):
> 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?
C does it that way. So, in general, does assembler, and the internal
representation of unsigned integer numbers runs from 0 to (2^bits)-1,
where bits is the number of bits of data storable.
Counting from 0 is counter-intuitive to humans, but so is much of
computer science. Ultimately, it's because Guido wanted it that way.
More information about the Python-list