Friday, March 10, 2023
HomeSoftware EngineeringLearn how to Reverse an Integer in Python

# Learn how to Reverse an Integer in Python

If you want to reverse an integer utilizing Python, then you are able to do the next:

## Possibility 1 – Mathematical Palindrome Test#

``````original_number = 123454321
copy_number = original_number
reversed_number = 0

whereas original_number > 0:
the rest = original_number % 10
reversed_number = reversed_number * 10 + the rest
original_number = original_number // 10

if copy_number == reversed_number:
print(copy_number, 'is a palindrome quantity')
else:
print(copy_number, 'will not be a palindrome quantity')
``````

## Possibility 2 – String Reversal Quantity Palindrome#

``````quantity = 123454321

if quantity == int(str(quantity)[::-1]):
print(quantity, 'is palindrome.')
else:
print(quantity, 'will not be palindrome.')
``````

## Possibility 3 – Checklist Reversal Quantity Palindrome#

``````original_number = 123454321
lst_number = checklist(str(original_number))
lst_number.reverse()
reversed_number = ''.be a part of(lst_number)

if (original_number == int(reversed_number)):
print(original_number, 'is palindrome.')
else:
print(original_number, 'will not be palindrome.')
``````
RELATED ARTICLES