Python Practice › If-Else Programs › Program 17
Check a palindrome string
Write a Python program to check whether a string is a palindrome, ignoring case.
Input
"jaj", "Madam", "python"
Output
jaj is a palindrome Madam is a palindrome python is not a palindrome
Approach
- Lower-case the text and compare it with its reverse.
Solution
for word in ["jaj", "Madam", "python"]: text = word.lower() if text == text[::-1]: print(word, "is a palindrome") else: print(word, "is not a palindrome")Output
jaj is a palindrome Madam is a palindrome python is not a palindrome
Line by line
Line 2
Lower-casing makes “Madam” read the same backwards.
Learn the concept
New to this topic? Read the lesson, then come back.