Python "why" questions

Russ P. russ.paielli at
Thu Aug 19 20:03:53 CEST 2010

On Aug 19, 9:07 am, "J.B. Brown" <jbbr... at> wrote:
> 2010/8/9 MRAB <pyt... at>:
> > Default User wrote:
> >> Not to prolong a good "food fight", but IIRC, many years ago in QBasic,
> >> one could choose
> >> or
> When I wrote my own C++ 2-D matrix class, I wrote a member function
> which did exactly this - allow you to specify the initial index value.
> Then users of my class (mainly my research lab coworkers) could
> specify whichever behavior they wanted.
> In terms of providing readable code and removing beginning programmer
> confusion, why not extend python lists by using something similar to
> (but not necessarily identical to)  the C++ STL containers:
> C++
> int myX[ ]  = { 1,2,3,4,5 };
> std::vector<int> vectorX( myX, &myX[  sizeof( myX ) - 1 ] );
> std::cout << vectorX.begin() << std::endl;
> std::cout << vectorX.end() << std::endl;
> Python
> x = [ 1 , 2 , 3 , 4 , 5 ]
> print x.first()
> print x.last()    ,

Many years ago I wrote a fairly comprehensive vector/matrix class in C+
+. (It was an exercise to learn the intricacies of C++, and I also
really needed it.) I used a system of offset pointers to realize
indexing that starts with 1.

Years later, after I had quit using it, I decided that I should have
just bit the bullet and let the indexing start with zero for
simplicity. I believe that zero-based indexing is a mistake, but
attempts to fix it require additional boilerplate that is prone to
error and inefficiency. Short of a major language overhaul, we are
essentially stuck with zero-based indexing.

But that doesn't mean we should pretend that it was the right choice.

For those who insist that zero-based indexing is a good idea, why you
suppose mathematical vector/matrix notation has never used that
convention? I have studied and used linear algebra extensively, and I
have yet to see a single case of vector or matrix notation with zero-
based indexing in a textbook or a technical paper. Also, mathematical
summation is traditionally shown as "1 to N", not "0 to N-1". Are
mathematicians just too simple-minded and unsophisticated to
understand the value of zero-based indexing? Or have you perhaps been

More information about the Python-list mailing list