输入123456,输出654321,两个都是int类型;
输入的参数为num/out,int类型;
返回值为int类型。
第一种:(传入的值为正整数)
out = 0 while num: out = out * 10 + num % 10 num /= 10 return out
第二种:
def reserve_num(num): remainder = 0 remainder = num %10 while num>1: num /= 10 if num > 0: remainder = remainder*10 + num %10 return remainder
运行结果:
if __name__ == ‘__main__‘: print reserve_num(543211) #输出112345
时间: 2024-10-13 04:29:11