Python Program to check a number is palindrome or not using a function


In this program, You will learn how to check a number is a palindrome or not using a function in Python.


Some list are: 11 22 121 12321

Example: How to check a number is palindrome or not using a function in Python

def reverse(n):
    rev = 0
    while n > 0:
        r = n % 10
        rev = rev * 10 + r
        n = int(n / 10)
    return rev

x = int(input("Enter a number:"))
result = reverse(x)

if result == x:
    print("Number is palindrome:", x)
else:
    print("Number is not palindrome:", x)

Output:

Enter a number:121
Number is palindrome: 121