Palindrome Number Check

Category: Python Basics

Write a Python program to check if a number is a palindrome. The program should take an integer as input and output a Boolean indicating whether or not the input is a palindrome.


Input: 12321 

Output: True

Input: 12345 

Output: False

A number is a palindrome if it remains unchanged when reversed. One way to do this is by converting the number to a string and comparing it with its reverse.

def is_palindrome(n):
return str(n) == str(n)[::-1]

print(is_palindrome(12321)) # Outputs: True
print(is_palindrome(12345)) # Outputs: False

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!