Why Python does *SLICING* the way it does??
Bernhard Herzog
bh at intevation.de
Wed Apr 20 12:14:04 EDT 2005
Torsten Bronger <bronger at physik.rwth-aachen.de> writes:
>> http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF
>
> I see only one argument there: "Inclusion of the upper bound would
> then force the latter to be unnatural by the time the sequence has
> shrunk to the empty one." While this surely is unaesthetical, I
> don't think that one should optimise syntax according to this very
> special case.
The other main argument for startig at 0 is that if you do not include
the upper bound and start at 1 then the indices i of a sequence of N
values are 1 <= i < N + 1 which is not as nice as 0 <= i < N.
opportunity for an off by one error.
Then there's also that, starting at 0, "an element's ordinal (subscript)
equals the number of elements preceding it in the sequence."
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/
More information about the Python-list
mailing list