Python Program to Check if a String is Palindrome or Not using For Loop
This examples shows, how to find a given string is palindrome or not. The string must be the same when inverted.it is a Palindrome . If the string does not remain unaltered when reversed, it is not a Palindrome
Steps
- Get the string input from user.
- A iterate through the append each element of the given string to the rev variable.
- Check if the given string matches the reverse string, it is palindrome.
Example:
Example.py
name = input("Enter the string : ") rev = "" for i in name: rev = i + rev if(name == rev): print("The string", name,"is a Palindrome.") else: print("The string",name,"is NOT a Palindrome.")
Output 1
Enter the string : malayalam The string malayalam is a Palindrome.
Output 2
Enter the string : hindi The string hindi is Not a Palindrome.