Write a program that reads a string and check whether it is a palindrome string or not.
Answer:
Code:
str=input(
"Enter a string: "
)
rev=str[::
-1
]
if str==rev:
print("Given string is a palindrome")
else:
print("Given string is not a palindrome")
Explanation:
A string is a palindrome if it reads the same forwards and backwards.
A string can be reversed in python using the slice operation . If we ignore both the indexes and give step size as -1, the string is printed in reverse.
Now the entered string and the reversed string are compared to check whether the string is a palindrome or not.