Write a program to Check Whether a String is Palindrome or Not in Python
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# Program to check if a string # is palindrome or not # change this value for a different output my_str = 'ababa' # 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(my_str," is palindrome") else: print(my_str," is not palindrome") |