by BehindJava
Write a program to check palindrome of a string in Python
In this tutorial we are going to learn about checking a palindrome of a String in Python.
Program to check palindrome of a string
a=input("enter sequence")
b=a[:: -1 ]]
if a==b:
print("palindrome")
else:
print("not palindrome")
Explanation
- user must enter a string and store it in a variable.
- The string is reversed using string slicing, it is compared to the non-reverse string.
- If both are equal, the strings are palindromes.
- If they aren’t equal, the strings aren’t palindromes.