Reverse Iteration Through Integers

alex23 wuwei23 at gmail.com
Mon Oct 19 02:04:36 EDT 2009


On Oct 19, 3:53 pm, Jabba Laci <jabba.l... at gmail.com> wrote:
> Would someone explain how str[::-1] work? I'm new to Python and I only
> saw so far the str[begin:end] notation. What is the second colon?

Slice notation is of the form [start:stop:step]. start defaults to the
start of the sequence, stop to the end, and step to 1.

So a slice of [::-1] returns the full sequence in reverse, stepping
back one character at a time from the end of the sequence to the
beginning.

The only mention I could find was http://docs.python.org/dev/3.0/library/functions.html#slice



More information about the Python-list mailing list