Reverse Iteration Through Integers

Chris Rebert clp2 at
Mon Oct 19 08:00:24 CEST 2009

On Sun, Oct 18, 2009 at 10:53 PM, Jabba Laci <jabba.laci at> wrote:
> Hi,
> 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?

Specifies the step value, as in:   foo[start:stop:step]

When not specified it, defaults to 1.
So foo[::-1] gives the entire sequence backwards.
Analogously, foo[::2] gives every other item in the sequence, forwards.


More information about the Python-list mailing list