Python Program to Check Palindrome

« Previous Program Next Program »

Check Palindrome in Python

To check whether the given number is a palindrome number or not a palindrome number in python, you have to ask from user to enter a number to check for palindrome number as shown in the program given here.

Palindrome number is an integer whose reverse is equal to the number itself, for example the reverse of 121 is equal to 121 which is the number itself, then it is a palindrome number, whereas the reverse of 123 is equal to 321 which is not equal to the number itself, that is 123, therefore it is not a palindrome number.

Python Programming Code to Check Palindrome

Following python program ask from user to check whether it is a palindrome number or not:

# Python Program - Check Palindrome Number or Not

print("Enter 'x' for exit.");
num = input("Enter any number to check for palindrome: ");
if num == 'x':
    number = int(num);
    orig = number;
    rev = 0;
    while number > 0:
        rev = (rev*10) + number%10;
        number //= 10;
    if orig == rev:
        print(orig, "is a Palindrome Number.");
        print(orig, "is not a Palindrome Number.");

Here is the sample run of the above Python program to illustrate how to check for palindrome number:

check palindrome number python

Now let's enter any number to find out whether it is a palindrome or not say 28982:

check palindrome or not python

Now re-run the same program again and this time check a number for palindrome say 28976:

check palindrome python

Below is the same program on python shell:

python check palindrome number

Program Video with Compile and Run

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test