Part of the series

Several example codes

~1 min read • Updated Sep 16, 2025

Program Overview

This Python program reads an integer from the user and checks whether it is palindromic.
A number is considered palindromic if it remains the same when its digits are reversed.


Python Code:


number = input("Please enter a number: ")

if number == number[::-1]:
    print("The number is palindromic.")
else:
    print("The number is not palindromic.")

Sample Output:


Please enter a number: 12321
The number is palindromic.

Please enter a number: 4567
The number is not palindromic.

Explanation:

Here’s how the program works:
- The number is read as a string so its digits can be reversed easily
- The slicing operation [::-1] is used to reverse the string
- If the original number matches its reversed version, it is palindromic
- The result is displayed using the print() function


Written & researched by Dr. Shahin Siami