Python "why" questions
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Aug 7 09:38:20 EDT 2010
More information about the Python-list mailing list
Sat Aug 7 09:38:20 EDT 2010
- Previous message (by thread): Python "why" questions
- Next message (by thread): Python "why" questions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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... > 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? -- Steven
- Previous message (by thread): Python "why" questions
- Next message (by thread): Python "why" questions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list