Skip to content

Instantly share code, notes, and snippets.

@MattyAyOh
Created January 4, 2016 18:35
Show Gist options
  • Save MattyAyOh/bb352ea7b66495fad5d0 to your computer and use it in GitHub Desktop.
Save MattyAyOh/bb352ea7b66495fad5d0 to your computer and use it in GitHub Desktop.
Reverse an integer in Python in place
inputNum = 1234
reverseNum = 0
while inputNum > 0:
reverseNum = (reverseNum*10) + (inputNum%10)
inputNum = inputNum/10
print reverseNum
@MattyAyOh
Copy link
Author

MattyAyOh commented Jan 4, 2016

Write a function that takes an integer, then reverses the digits in the integer, and returns that reversed integer

Example: 123 -> 321; 5034 -> 4305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment