Python program to check if a string is palindrome or not

Problem Definition

Make a Python program to check if the given string is palindrome or not. A string is a palindrome if it reads same from forward as well as backward for example madam.


  1. Take the input string from the user and store it in a variable
  2. Reverse the string and compare it to the base string
  3. Print the result
  4. End


word = input("Enter a number : ")
word = word.casefold()

if(word == word[: : -1]):
    print("Not Palindrome")

Runtime Test Cases

Enter a number : madam

Additional Explanation

The casefold() method is used to implement caseless string matching. It is similar to lower() string method but case removes all the case distinctions present in a string. i.e ignore cases when comparing hence this program will work for both the following strings Madam and madam.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *