Palindrome Number Check
Check whether an integer is a palindrome using digit reversal.
BeginnerTopic: Loop Programs
Python Palindrome Number Check Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to check palindrome number
num = int(input("Enter an integer: "))
temp = abs(num)
rev = 0
while temp > 0:
digit = temp % 10
rev = rev * 10 + digit
temp //= 10
if num >= 0 and rev == num:
print(num, "is a palindrome")
else:
print(num, "is not a palindrome")Output
Enter an integer: 121 121 is a palindrome
Understanding Palindrome Number Check
We reverse the digits and compare with the original number; for simplicity, we treat negative numbers as non-palindromes.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.