Skip to main content.
September 23rd, 2006

Super Easy Way to Reverse a String in Python

Here’s what I discoved today. To reverse a string in Python you just do:
text[::-1]

It’s that easy! Here is a more filling example:

>>> text='greg'
>>> print text[::-1]
gerg

And finally here is why it works, for the curious.

Posted by Greg Pinero (Primary Searcher) in Python

This entry was posted on Saturday, September 23rd, 2006 at 5:35 pm and is filed under Python. You can follow any responses to this entry through the comments RSS 2.0 feed. Both comments and pings are currently closed.

One Response to “Super Easy Way to Reverse a String in Python”

  1. Big Bad Code » Python reverse string method says:

    […] Saw this easy way to reverse a string in python today, over at Answer My Searches […]