# Python program to check whether a number is Palindrome or not

A simple python program which checks whether a number is a palindrome or not.
Generally, a number is said to be a palindrome number if its reverse is same as the original number.

For Example, 121 is a palindrome as its reverse is also 121 whereas, 231 is not a palindrome as its reverse is 132.

You can watch the video on YouTube here

#### Palindrome number – Code Visualization

To check whether a number is palindrome or not

#### Approach :

• Read an input number using `input()` or `raw_input()`.
• Check whether the value entered is integer or not.
• We convert that integer number to string `str(num)`.
• Now we use advanced slice operation `[start:end:step]` leaving start and empty and giving step a value of -1, this slice operation reverses the string.
• Now check whether reverse is equal to num,
• If `reverse` is equal to `num`, the number is palindrome
• When `reverse` is not equal to `num`, it is not a palindrome

#### Output :

Please feel free to check other math related programs here or some basic programs here.

##### Course Suggestion

Want to be strong at OOP in Python? If yes, I would suggest you to take the course below.
Course:
Object Oriented Programming in Python

1. Yakhya Torshkho

Sorry, I am newbee in programming.
How can int object and reversed str object be the same?

2. Yakhya Torshkho

Oh sorry, thats my carelessness

3. Yakhya Torshkho

Why do we need tor str the num variable on the fourth line?

1. avinash

We can also do it without using slice operations, by using arithmetic operations http://programminginpython.com/python-program-to-find-reverse-of-a-number/ Similar to reverse.Here we check if reverse is the same number.

if true then it is a palindrome.

4. avinash

Here we converted int to string,

5. avinash

Here we used slice operation [::-1] which can be applied to strings so we converted an int to string.

6. Pingback: URL

This site uses Akismet to reduce spam. Learn how your comment data is processed.