Reverse a String
Reverse a string entered by the user.
BeginnerTopic: String Programs
Python Reverse a String Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to reverse a string
s = input("Enter a string: ")
reversed_s = s[::-1]
print("Reversed string:", reversed_s)Output
Enter a string: hello Reversed string: olleh
Understanding Reverse a String
We use Python's slicing syntax `s[: :-1]` to create a reversed copy of the string.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.