Welcome to the Treehouse Community
Looking to learn something new?
Andrew Merrick20,151 Points
Ways to reverse a string in Python?
This is in reference to the Stringcases challenge in the Tuples section of Python collections: http://teamtreehouse.com/library/stringcases
I was able to pass but I was wondering if there's a built in method to reverse a string, i.e. my_string.reverse()?
my_string.reverse() and my_string.reversed()
did not work since, I believe, they only apply to lists. I found out another way using slicing, but is there a method to reverse a string in Python?
Stone Preston42,016 Points
I think you can use
if you dont want to use slicing
Pierre Guiglion11,583 Points
You can also use:
It actually "slices" your string, going through all of it, by steps of -1. The slicing syntax is: