To reverse a string entered by the user in python, you have to ask from user to enter the desired string which is going to reverse to reverse that string and print the reversed string as output as shown in the program given below.
Following python program ask from the user to enter a string to reverse that string and print it as output:
# Python Program - Reverse String while True: print("Enter 'x' for exit.") string = input("Enter any string: ") if string == 'x': break else: revstring = string[::-1] print("Reverse String =",revstring,"\n")
Here is the sample run of the above python program to illustrate how to reverse a string in python:
You may also like to learn or practice the same program in other popular programming languages: