► Python program to find if a string is palindrome or not(python way)


palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward

Steps followed:
1. take input from user and store in var variable
2. reverse the input string using slicing
3. print reverse string
4. compare input string and reversed string to check for palindrom


Program

#python program to find if a string is palindrome or not(python way)

#getting input from user and storing in var variable
var=input("Enter a string: ")

rev=""

#reverse the input string and store in rev variable
rev = var[::-1]    

#print reverse string
print("reverse of input string %s"%(rev))

#compare input string and reverse string to check for palindrom
if var == rev:
    print("Palindrome")
else:
    print("Not Palindrome")


Output

Enter a string: start
reverse of input string trats
Not Palindrome

 

Enter a string: radar
reverse of input string radar
Palindrome





Also Read: