Skip to main content

Palindrome Check Program in Python

In our previous Python tutorial, you have learned to create Fibonacci Series in Python. In this tutorial, we will explain how check whether a number or string is Palindrome.

A palindrome is a number or letter that remains the same even if the number and string are reversed.

For example, if we reverse below numbers, it will remain same.

121
12321
74747 

below strings will also remain same after reversed.

MOM
DAD
MADAM

So all these numbers and strings are palindrome.

Palindrome Number Check Program Python

Here we will implement with while loop to check if number is Palindrome or not.

number = int(input("\nEnter number:"))
originalNumber = number

reverse = 0
while(number > 0):
    digit = number % 10
    reverse = reverse * 10 + digit
    number = number // 10
if(originalNumber == reverse):
    print("\nThe number is palindorme!")
else:
    print("\n The number isn't a palindorme!")

Palindrome String Check Program Python

Here we will check whether user inputted string is Palindrome.

string = input("\nEnter string:")

string = string.casefold()

reversedString = reversed(string)

if list(string) == list(reversedString):
   print("The string is a palindrome.")
else:
   print("The string is not a palindrome.")