string[i:j:k]

John McMonagle jmcmonagle at velseis.com.au
Tue Jul 22 02:05:46 EDT 2008


konstantin wrote:

> 
> Thanks!
> It seems that negative step leads in reverse direction.
> But logic isn't completely clear for me.
>>>> s = '123456789'
>>>> s[::-2]
> '97531'
> 
> but
>>>> s[:-1:-2]
> ''
> though I expected something like '8642'
> What did i missed?
> 
> --


You need to *start* at the second from last index:

s[-2::-2]

Regards,

John



More information about the Python-list mailing list