Determine if the string is palindrome

Question:

This function takes a string as input and returns True if string is palindrome and
False otherwise. A palindrome is a symmetric sequence of characters, reading
the same forward and backward.
For example: radar, anna, mom, dad, …

Asked By: whitecat

||

Answers:

You can do this like the below:

def is_palindrome(phrase):
    string = ""
    for char in phrase:
        if char.isalnum():
            string += char
    print(string)
    return string[::-1].casefold() == string.casefold()


word = input("Please enter a word to check: ")
if is_palindrome(word):
    print("'{}' is a palindrome".format(word))
else:
    print("'{}' is not a palindrome".format(word))
Answered By: Raed Ali
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.