Saturday, March 11, 2023
HomeSoftware EngineeringThe right way to Reverse an Integer in Python

# The right way to Reverse an Integer in Python

If it’s essential to reverse an integer utilizing Python, then you are able to do the next:

## Choice 1 â€“ Mathematical Palindrome Examine#

``````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, 'just isn't a palindrome quantity')
``````

## Choice 2 â€“ String Reversal Quantity Palindrome#

``````quantity = 123454321

if quantity == int(str(quantity)[::-1]):
print(quantity, 'is palindrome.')
else:
print(quantity, 'just isn't palindrome.')
``````

## Choice 3 â€“ Listing Reversal Quantity Palindrome#

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

if (original_number == int(reversed_number)):
print(original_number, 'is palindrome.')
else:
print(original_number, 'just isn't palindrome.')
``````

RELATED ARTICLES