Python "why" questions
Thomas Jollans
thomas at jollans.com
Sat Aug 7 10:29:16 EDT 2010
On 08/07/2010 03:38 PM, Steven D'Aprano wrote:
> On Sat, 07 Aug 2010 14:00:59 +0200, Thomas Jollans wrote:
>
>> On 08/07/2010 05:05 AM, Default User wrote:
>>> >From "the emperor's new clothes" department:
>>>
>>> 1) Why do Python lists start with element [0], instead of element [1]?
>>> "Common sense" would seem to suggest that lists should start with [1].
>>
>> As others have pointed out, there is a nice argument to be made for
>> zero-based indices. However, the killer reason is: "it's what everybody
>> else does."
>
> I'll have you know that there are still some Pascal programmers in the
> world, thank you.
>
>
>
>> As it stands, the only perceived problem with zero-based
>> indices is that it's one of the many tiny confusions that new
>> programmers face. On the other hand, it's the way nearly every other
>> popular programming language does it, and therefore, it's the way almost
>> every programmer likes to think about sequences.
>
> It didn't take me long to get used to thinking in zero-based indexes, but
> years later, I still find it hard to *talk* in zero-based indexes. It's
> bad enough saying that the first element in a list in the zeroth element,
> but that the second element is the first makes my head explode...
zeroth
oneth
twoth
;-)
(element no. one is a better way of pronouncing it.)
>
>
>> Also, it has the nice property that, for an infinite sequence, every
>> integer makes sense as an index (in Python).
>
> Er, what's the -1th element of an infinite sequence?
well, it's the first from the other end. The infinite bit is in between,
thank you very much. ;-)
More information about the Python-list
mailing list