Python Practice › String Programs › Program 25

Check a palindrome string

EasyString Programs · 25 of 106

Check whether a given string is a palindrome.

Advertisement
Input
"sqatoolssqatools", "racecar"
Output
sqatoolssqatools is not a palindrome
racecar is a palindrome

Approach

  1. Compare the string with its reverse.

Solution

Python
for s in ["sqatoolssqatools", "racecar"]:    print(s, "is a palindrome" if s == s[::-1] else "is not a palindrome")
Output
sqatoolssqatools is not a palindrome
racecar is a palindrome

Learn the concept

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

More string programs

← All 106 String Programs

Leave a Comment