Write a Python program to reverse a given string:-
str=input("Enter the string : ")
print('THE REVERSE OF THE STRING IS :- ',str[::-1])
Output :
Enter the string : PRIYA
THE REVERSE OF THE STRING IS :- AYIRP
This is a Python code that takes a string as input from the user, then prints the reverse of the string using slicing. Here's how the code works:
The input() function is used to take input from the user. Whatever the user types in are stored in the variable 'str'.
The slicing notation [::-1] is used to reverse the string. The notation means "Start at the end of the string and keep going back until the beginning, with a step of -1". This results in the string being reversed.
The reversed string is then printed using the print() function.
If you are a beginner and want to know more about Python programming, you can read my Basics of Python blogs (From part 1 to part 15).
HAPPY LEARNING !!!