Author Topic: Python - How to reverse a string?  (Read 886 times)


  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Python - How to reverse a string?
« on: December 06, 2011, 05:25:00 pm »
Here is the python source code to reverse the string.

Code: (Python)
#Python Source File

# [::-1] is used to reverse the string
def ReverseString(inpstr):
        print (inpstr,"reversed to", revstr) #paranthesis are required for new version
	return inpstr[::-1] 

#end of the function

Here is how you import and execute the code

>>>import mycode
>>> mycode.ReverseString("Kathir")
Kathir reversed to rihtaK


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1