Learn about Palindrome Number using Slicing in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view of what’s actually happening.
This Python program determines whether or not a given number is a Palindrome. A palindrome number is one whose digits remain the same when they are reversed.
Contents
Palindrome Number using Slicing in Python
Initially, the input number is read from the user. The number is reversed using string slicing and checked whether it’s equal to the given number.
Program :
# Python program to check if number is Palindrome using slicing
# input number
num = int(input('Enter the number: '))
# reverse of number
reverse = int(str(num)[::-1])
# compare reversed number to original number
if(num == reverse):
print(num,'is a Palindrome')
else:
print(num,'is not a Palindrome')
Output:
Enter the number: 121
121 is a Palindrome
Enter the number: 123
123 is not a Palindrome
Hope the above code works for you and Refer to the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code: Palindrome Program in Python using Recursion