Here we will write a program to check whether the string is palindrome or not in Python.
A palindrome is a string which is same read forward or backwards.
For example: “dad” is the same in forward or reverse direction. Other example is ‘Malayalam’ etc.
Python program to check if String is Palindrome or not:
# Program to check if a string
# is palindrome or not
# change this value for a different output
my_str = 'malayalam'
# make it suitable for caseless comparison
my_str = my_str.casefold()
# reverse the string
rev_str = reversed(my_str)
# check if the string is equal to its reverse
if list(my_str) == list(rev_str):
print("It is palindrome")
else:
print("It is not palindrome")OUTPUT:
It is palindrome
Please comment for any suggestion or concerns.