[Tutor] slicing a string
lists
lists at justuber.com
Tue Sep 7 00:14:59 CEST 2010
Hi guys,
Continuing my Python learning, I came across an exercise which asks me
to take a string and reverse it.
I understand that there is a function to do this i.e mytext.reverse()
I imagine that the exercise author would rather I did this the hard
way however. ;-)
Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
doesn't work (as I expected it to) but that mytext[::-1] does.
While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work?
Thanks again,
Chris
More information about the Tutor
mailing list