inclusive-lower-bound, exclusive-upper-bound (was Re: Range Operation pre-PEP)
Andrew Maizels
andrew at one.net.au
Fri May 11 04:46:24 EDT 2001
Aahz Maruch wrote:
>
> In article <3AFB0DB9.BDAE54A5 at one.net.au>,
> Andrew Maizels <andrew at one.net.au> wrote:
> >
> >I can see where consistency is important, but why does Python do the
> >inclusive-lower-bound, exclusive-upper-bound thing?
>
> Because it makes loops more likely to work. E.g.:
>
> l = [1,4,9,16]
> for i in range(len(l)):
> print l[i]
OK, next question: why does Python start indexes at zero? Your example
would work perfectly well if the range returned [1, 2, 3, 4] and the
list was indexed starting with 1. Basically, range(4) has to produce a
list of four items, we just differ on what those items should be.
I'm not just being difficult; I'm trying to design my own language, and
this is one of the things I have different to Python. If I've missed
something where the Python way is superior, then I might want to change
my mind.
The way I have things at the moment, in Pixy (my language), array
indexes default to start at 1, but can be declared to any range (like
Pascal). Strings are indexed starting with 1 as well. Is there a good
reason not to do this?
Andrew.
--
There's only one game in town.
You can't win.
You can't break even.
You can't quit the game. -- The four laws of thermodynamics.
More information about the Python-list
mailing list