[Python-ideas] Where did we go wrong with negative stride?

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Oct 29 06:05:36 CET 2013


Terry Reedy wrote:
> I have forgotten whatever explanation was given, 
> but their parameters have different meanings. For slices, start and stop 
> are symmetrical and both mark boundaries between what is included and 
> what is excluded. For ranges, start and stop are symmetrical; one is 
> included and the other excluded.

I don't think that's the difference; you can equally well
think of the parameters to range as delineating a slice of
an infinite list of integers.

The real difference is in how negative numbers are
interpreted: range(-2, 3) gives [-2, -1, 0, 1, 2],
whereas slicing does something special with the -2.

-- 
Greg


More information about the Python-ideas mailing list