倒序一个整数
例如 1234 --> 4321
def intrev(i):
a = []
sum = 0
while(i>0):
a.append(i%10)
i = (i-i%10)/10
for i in range(len(i)):
sum=sum*10+a[i]
return sum
进阶版去掉列表
def intrev(i):
sum = 0
while (i>0):
sum = sum*10+i/10
i = i//10
return sum
Pyhton魔性版 通过字符串倒序
def intrev(i):
return int(str(i)[::-1])
网友评论