# [Python-ideas] [Python-Dev] Inclusive Range

Terry Reedy tjreedy at udel.edu
Tue Oct 5 23:41:03 CEST 2010

```On 10/5/2010 4:54 AM, Carl M. Johnson wrote:
> Changing range would only make sense if lists were also changed to
> start at 1 instead of 0, and that's never gonna happen. It's a
> massively backwards incompatible change with no real offsetting
>
> Still, if you were designing a brand new language today, would you
> have arrays/lists start at 0 or 1? (Or compromise and do .5?) I
> personally lean towards 1, since I recall being frequently tripped up
> by the first element in an array being a[0] way back when I first
> learn C++ in the 20th century. But maybe this was because I had been
> messed up by writing BASIC for loops from 1 to n before that? Is there
> anyone with teaching experience here? Is this much of a problem for
> young people learning Python (or any other zero-based indexing
> language) as their first language?
>
> What do you guys think? Now that simplifying pointer arithmetic isn't
> such an important consideration, is it still better to do zero-based
> indexing?

Sequences are often used as and can be viewed as tabular representations
of functions for equally spaced inputs a+0*b, a+1*b, ..., a+i*b, .... In
the simplest case, a==0 and b==1, so that the sequence directly maps
counts 0,1,2,... to values. Without the 0 index, one must subtract 1
from each index to have the same effect. Pointer arithmetic is an
example of the utility of keeping the 0 term, but only one such example
of many.

When one uses iterators instead of sequences, as in more common in
Python 3, there is no inherent index to worry about or argue over.

def inner_product(p,q): # no equal, finite len() check!
sum = 0
for a,b in zip(p,q):
sum += a*b

No index in sight.

--
Terry Jan Reedy

```