Python中两个变量交换

如果有a,b两个变量,一般交换时,会选用一个临时变量:

temp = a

a =b

b = temp

但是python中可以不使用临时变量:

a, b = b, a

这样可以直接完成a,b的交换。