[Tutor] Thanks re: [::-1]

Charles Cuell cuell at snoopy.usask.ca
Thu Jul 26 19:32:57 CEST 2007

Thanks to everybody that worked to clarify the meaning of [::-1].

My main concern was that it looked like the notation came out of nowhere
and, as such, was inconsistent with the usual slice notation.  The
documentation did make it clear, since the full slicing notation is
s[i:j:k], leaving out the i and j to indicate starting at the
beginning and stopping at the end results in s[::k].

The one odd thing about Python's slice notation is that the -1 means to
start from the end and work backwards.  My first inclination would have
been to assume that -1 means to start at i and go to j by steps of -1
(only nonempy if j < i).

Thanks again.

Charles Cuell
cuell at math.usask.ca

More information about the Tutor mailing list