while True:
n=str(input())
if len(str(int(n))) == len(n):
print(int(n[::-1]))
else:
print('前导符不能为0!')
n = eval(intpu())res = 0
while n >0:
res = res * 10 + n %10
n = n // 10
print(res)
[::-1]实现翻转功能。Python 的切片功能实际上比很多程序员认为的更强大。
a = m [ 0 : 100 : 10 ] # 带步进的切片(步进值=10)
注意:步进值为step
当step >0 时
切片从 start(含start)处开始,到end(不含end)处结束,**从左往右**,每隔(step-1)(索引之间的差仍为step,但相隔的元素是step-1个)个元素进行一次截取。
这时,start 指向的位置应该在end指向的位置的左边,否则返回值为空
当step <0 时
切片从 start(含start)处开始,到end(不含end)处结束,**从右往左**,每隔(step-1)(索引之间的差仍为step,但相隔的元素是step-1个)个元素进行一次截取。
这时,start 指向的位置应该在end指向的位置的右边,否则返回值为空