Python "why" questions

geremy condra debatem1 at gmail.com
Thu Aug 19 16:12:13 EDT 2010


On Thu, Aug 19, 2010 at 12:32 PM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> On Thu, 19 Aug 2010 11:57:53 -0700, Russ P. wrote:
>
>> I don't
>> know where zero-based indexing started, but I know that C used it very
>> early, probably for some minuscule performance advantage.
>
> In C, zero based indexing was used because it made pointer arithmetic
> elegant and reduced bugs.

That's because in C, an array 'index' is not an ordinal, but a
distance. Distances are easier to work with if you are comparing
indices and performing arithmetic on them, while ordinals are easier
to work with for straightforward I'd-like-this-element-please. I'm
personally glad that Python uses the former.

Geremy Condra



More information about the Python-list mailing list