Reverse the digits of an integer, keeping its sign. Leading zeros in the result are dropped (e.g. 120 → 21).
Input
A single integer (it may be negative).
Output
The integer with its digits reversed.
Reverse the digits of an integer, keeping its sign. Leading zeros in the result are dropped (e.g. 120 → 21).
A single integer (it may be negative).
The integer with its digits reversed.
Example 1
123
321
123 → 321.
Example 2
-45
-54
Sign kept: -45 → -54.
Example 3
120
21
Trailing zero becomes leading and is dropped: 120 → 21.
Handle the sign separately, then reverse the digit characters.
Converting the reversed digit string back to an integer naturally drops leading zeros.
Split off the sign, reverse the digit characters of the absolute value, parse back to an integer, and reapply the sign.
s = input().strip()
sign = -1 if s[0] == '-' else 1
digits = s.lstrip('-')
print(sign * int(digits[::-1]))
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.