more newbie help needed
Craig Marshall
craig9 at gmail.com
Mon Nov 14 14:49:42 EST 2005
> Note, however, that there are more pythonic ways to perform this task.
> You might try:
>
> for index in range(len(fruit)):
> letter = fruit[-index-1]
> print letter
Or, if you're *really* just trying to reverse the string, then the
following might read more easily (although it's probably longer):
fruit="banana"
fruit = list(fruit)
fruit.reverse()
fruit = ''.join(fruit)
print fruit
It turns the string into a list, reverses it, joins it back together
(back into a string), then prints it.
Craig
More information about the Python-list
mailing list