python example

Palindrome check in Python

Test whether a string is a palindrome after normalizing case and spaces.

Build a lowercase alphanumeric version, then compare it to its reverse with slicing ([::-1]).

Try a sentence with spaces and punctuation. If the function returns False, print the normalized string to see why.

def is_palindrome(text):
    normalized = "".join(ch.lower() for ch in text if ch.isalnum())
    return normalized == normalized[::-1]

print(is_palindrome("Never odd or even"))
print(is_palindrome("Code Arena"))