Check Palindrome Number in Python

Beginner
⏱️ 8 min read
📚 Updated: May 2026
🎯 2 Code Examples
Digit reversal

What you’ll learn

  • What a palindrome number is.
  • How to reverse digits using % 10 and // 10.
  • How to print palindrome numbers from 100 to 200.

Overview

A palindrome number has mirrored digits. If reversing the digits gives the same number, it is a palindrome.

Single check

Check values like 121 and 12321.

Range scan

Print all palindromes between 100 and 200.

Live preview

Test a nonnegative integer instantly.

Prerequisites

while loops, integer arithmetic, and modulo operation.

  • Basics of Python functions with def.
  • Knowing that % 10 gives last digit and // 10 removes it.

The idea

Take the last digit, append it to a reversed value, and remove it from the original number. Repeat until no digits remain.

If reversed value equals original starting value, the number is palindrome.

Live preview

Enter a nonnegative integer and check whether it is palindrome.

Try 121, 123, 0, or 7.

Live result
Press "Check palindrome".

Algorithm

Goal: check whether decimal digits of a number are symmetric.

Save original number

Keep input value before modifying it.

Reverse digits with loop

Use digit = n % 10, then rev = rev * 10 + digit, and n //= 10.

Compare

If original == reversed, it is palindrome.

📜 Pseudocode

Pseudocode
function is_palindrome(n):
    original = n
    reversed = 0
    while n != 0:
        reversed = reversed * 10 + (n mod 10)
        n = floor(n / 10)
    return original == reversed
1

Check one number

Use arithmetic reversal and compare with original.

python
def is_palindrome(number: int) -> bool:
    original_number = number
    reversed_number = 0

    while number != 0:
        remainder = number % 10
        reversed_number = reversed_number * 10 + remainder
        number //= 10

    return original_number == reversed_number


number = 121
if is_palindrome(number):
    print(f"{number} is a palindrome number.")
else:
    print(f"{number} is not a palindrome number.")

Explanation

The loop reconstructs the number in reverse order and compares it with the original saved value.

2

Palindromes from 100 to 200

Reuse the same helper inside an inclusive range loop.

python
def is_palindrome(num: int) -> bool:
    original_num = num
    reversed_num = 0

    while num != 0:
        remainder = num % 10
        reversed_num = reversed_num * 10 + remainder
        num //= 10

    return original_num == reversed_num


print("Palindrome numbers in the range 100 to 200:")
for i in range(100, 201):
    if is_palindrome(i):
        print(i, end=" ")

Explanation

Python range uses exclusive end, so use 201 to include 200.

Notes

No overflow issue in Python ints. Python integers can grow beyond 32-bit limits.

String alternative. You can also check palindrome using text comparison, but arithmetic method is a classic interview approach.

❓ FAQ

A palindrome number reads the same from left to right and right to left, like 121 or 9009.
Reversing digits gives a value you can directly compare with the original using ==.
Yes. Any single-digit number is palindrome.
Yes. Zero reads the same in both directions.
This lesson uses nonnegative integers. You can define separate behavior for negatives if required.
Checking one number is O(d) where d is digit count. Range scan multiplies this by number of tested values.

🔄 Input / output examples

Try these values with the single-value helper.

ValuePalindrome?
0Yes
7Yes
121Yes
123No (321)

Edge cases

Trailing zeros

120 and 21

Reversal removes leading zeros, so 120 is not palindrome.

Single digit

n < 10

Always palindrome for nonnegative numbers.

Negative input

Define behavior clearly

This page rejects negative values in live preview for beginner clarity.

⏱️ Time and space complexity

OperationTimeExtra space
is_palindrome(n)O(d)O(1)
Range [a, b]O((b-a+1) * d)O(1)

Summary

  • Core trick: reverse digits and compare with original.
  • Range scan: reuse same helper for each candidate.
  • Watch-outs: trailing zeros and negative input rules.
Did you know?

The word palindrome also describes words like “radar” or “level”. For integers, we compare digits only, so single-digit values like 7 always pass.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful