HomeSoftware EngineeringHow you can Reverse an Integer in Python

How you can Reverse an Integer in Python

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

Choice 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, '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, 'isn't palindrome.')
``````

Choice 3 – Record Reversal Quantity Palindrome#

``````original_number = 123454321
lst_number = listing(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, 'isn't palindrome.')
``````
RELATED ARTICLES