Check a palindrome string

EasyIf-Else Programs · 17 of 64

Write a Python program to check whether a string is a palindrome, ignoring case.

Advertisement
Input
"jaj", "Madam", "python"
Output
jaj is a palindrome
Madam is a palindrome
python is not a palindrome

Approach

  1. Lower-case the text and compare it with its reverse.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs