import math
class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
strX = str(x)
if strX[0] != '-':
strX1 = strX[::-1]
x = int(strX1)
if x >-2147483648 and x <2147483647:
x = x
else:
x = 0
else:
strX1 = strX[1:][::-1]
x = -1*int(strX1)
if x >-2147483648 and x <2147483647:
x = x
else:
x = 0
return x
注意:
1 python自带的字符串操作
2 注意判断溢出,判断正负号
3 python中的与操作是and而不是&