# Python 中反轉整數

## 在 Python 中使用數學方法檢查數字是否為迴文

``````# python 3.x
original_number = int(input("Enter an integer: "))
copy_number = original_number
reversed_number = 0
while original_number > 0:
remainder = original_number % 10
reversed_number = reversed_number * 10 + remainder
original_number = original_number // 10
if copy_number == reversed_number:
print(copy_number, "is a palindrome number")
else:
print(copy_number, "is not a palindrome number")
``````

``````Enter an integer: 12321
12321 is a palindrome number
``````

## 在 Python 中使用字串反轉方法檢查數字是否為迴文

``````# python 3.x
number = int(input("Enter a number : "))
if number == int(str(number)[::-1]):
print(number, "is palindrome.")
else:
print(number, "is not palindrome.")
``````

``````Enter a number : 454
454 is palindrome.

Enter a number : 456
456 is not palindrome.
``````

## 在 Python 中使用列表反轉方法查詢數字是否為迴文

``````# python 3.x
original_number = int(input("Enter an integer : "))
lst_number = list(str(original_number))
lst_number.reverse()
reversed_number = "".join(lst_number)
if original_number == int(reversed_number):
print(original_number, "is palindrome.")
else:
print(original_number, "is not palindrome.")
``````

``````Enter an integer : 99
99 is palindrome.
``````