Giveaway of Udemy Web Development Course Click Here!

# Palindrome Program in Python using for loop [New]

In this program, we are going to check whether the number or string is a palindrome or not, using for loop and also using reversed() function.

In this program, we will check whether the number or string is a palindrome or not in python, using for loop and also using reversed() function.

## Palindrome program in python for numbers using for loop

```number=input("Enter any number :")
i=0
for i in range(len(number)):
if number[i]!=number[-1-i]:
print('It is not a palindrome')
break
else:
print('It is a palindrome')
break```
Output:

Enter any number:5665
It is a palindrome

## Palindrome program in python using string

```word=input("Enter any word :")
rev=reversed(word)
if list(word)==list(rev):
print('It is a palindrome')
else:print('It is not a palindrome')```
Output:

Enter any word: madam
It is a palindrome

### Approach for Palindrome program in python using string:

• First, we input the string using the input() function.
• Using the reversed() function, we reverse the word entered by the user and assign it to a new variable called rev.
• Using the if statement, we compare the list(word) & list(rev). If they are the same, then we will print "it is a palindrome", and if they are not the same, we will print "it is not a palindrome".

## Palindrome program in python for numbers using reversed() function

```number=input("Enter any number :")
rev=reversed(number)
if list(number)==list(rev):
print('It is a palindrome')
else:print('It is not a palindrome')```
Output:

Enter any number:7887
It is a palindrome

### Approach for Palindrome program in python for numbers using reversed() function:-

• First, we input the string or number using the input() function.
• Using the reversed() function, we reverse the number or word entered by the user and assign it to a new variable called rev.
• Using the if statement, we compare the list(number or word) & list(rev). If these strings are the same, then we will print it as a palindrome; if they are not the same, then we will print it as not a palindrome.

Q. What is a palindrome number in python?

A number is a palindrome when its reverse is also the same as the original number.

To check whether a number is palindrome or not, we have to reverse the number using the reversed() function. Then we compare the true and reversed numbers using the if statement.

for example:8558, is a palindrome

Q. How do you write a palindrome program in python using for loop?

First, we input a number using the input() function, then reverse it using the reversed() function. Then we compare the number (or a word) with its reverse if the actual number and the reversed number are the same, then we print the number entered as a palindrome. Else, we print the number entered is not a palindrome.