Check String is Palindrome in Python

  • Post category:String

A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurse run. To check if a string is palindrome, you can reverse the string using str[::-1].

Step 1: Create a string

str = "refer"
print("str = ", str)
print("str type = ", type(str))

Step 2: Check if string is a palindrome

if str == str[::-1]:
    print("Palindrome")
else:
    print("Not Palindrome")
str =  refer
str type =  <class 'str'>
Palindrome

Free resources to learn advanced skills: AiHints and CodeAllow