negative stride list slices

Batista, Facundo FBatista at uniFON.com.ar
Wed Sep 1 13:57:34 EDT 2004


[dave at boost-consulting.com]

#-   >>> print range(10)[:-3:-1]
#-   [9,8]
#- 
#- I found this result very surprising, and would just like to see the
#- rules written down somewhere.

Slice objects
    Slice objects are used to represent slices when extended slice syntax is
used. This is a slice using two colons, or multiple slices or ellipses
separated by commas, e.g., a[i:j:step], a[i:j, k:l], or a[..., i:j]. They
are also created by the built-in slice() function.

    Special read-only attributes: start is the lower bound; stop is the
upper bound; step is the step value; each is None if omitted. These
attributes can have any type.

(from http://www.python.org/dev/doc/devel/ref/types.html#types)

.	Facundo



More information about the Python-list mailing list