Check Palindrome String in Python
Check whether a given string is a palindrome (ignoring case and spaces).
BeginnerString ProgramsExample 2 of 25
check-palindrome-string.py
Run in browser1# Program to check if a string is a palindrome23s = input("Enter a string: ")45normalized = "".join(ch.lower() for ch in s if not ch.isspace())67if normalized == normalized[::-1]:8 print("Palindrome")9else:10 print("Not a palindrome")
Output
Enter a string: Never odd or even Palindrome
What's going on
We normalize by:
Lowercasing all characters
Removing spaces
Then we compare the string to its reverse using slicing.