Friday 7 October 2022

Find a string is Palindrome or not

my_str = "AbcdDCBa"

#for caseless comparison
my_str = my_str.casefold()

#Reverse a string
rev_str = reversed(my_str)

if list(my_str) == list(rev_str):
    print("It is a palindrome")
else:
        print("It is not a palindrome")

No comments:

Post a Comment