[Tutor] IndexError: string index out of range

Michael Janssen mi.janssen at gmail.com
Wed Nov 3 15:00:05 CET 2004


On Tue, 2 Nov 2004 14:28:46 -0800 (PST), Danny Yoo
<dyoo at hkn.eecs.berkeley.edu> wrote:

> For this particular example, I'd actually recommend using a backwards
> slice.  Here's an example:

> >>> message = 'this is a test of the emergency broadcast system'

> >>> message[::-1]
> 'metsys tsacdaorb ycnegreme eht fo tset a si siht'

indeed reversing via extended slice is handy sometimes. Nevertheless I
allways feel like adding a comment that reads "now comes silly
extended slice syntax, which means I reverse the string - sorry for
that, dear reader". Not to talk about all the time I have spend /
wasted while figuring out the right syntax (my first try was [-1:0:-1]
;-). A little bit it seems like line noise...

Michael


More information about the Tutor mailing list