交换两个数的值的简单方法

a,b=10,20

print(a,b)

a,b=b,a#把b赋值给a,把a赋值给b

print(a,b)

#打印结果如下

#10 20
#20 10

你可能感兴趣的:(python)