[Tutor] IndexError: string index out of range

Eri Mendz jerimed at myrealbox.com
Wed Nov 3 09:01:14 CET 2004


On Tue, 2 Nov 2004, Danny Yoo wrote:

[snip]

> And it turns out that we can select a negative step:
>
> ###
>>>> message[::-1]
> 'metsys tsacdaorb ycnegreme eht fo tset a si siht'

i have seen this syntax before in one of my study guides, and is awesome:

>>> for i in fruit[::-1]:
....     print [index], '\t', i
....     index = index - 1
....
[-1]    a
[-2]    n
[-3]    a
[-4]    n
[-5]    a
[-6]    b

so now i realize in python "TIMTOWDI"... very nice, thanks guys!
now back to my tutorial; i will encapsulate this in a function and
generalize, e.g., to ask for user input and reverse the input.




More information about the Tutor mailing list