在Python中,有以下几种方法可以交换两个数的值:
a = 1 b = 2 temp = a a = b b = temp
a = 1 b = 2 a = a + b b = a - b a = a - b
a = 1 b = 2 a = a ^ b b = a ^ b a = a ^ b
a = 1 b = 2 a, b = b, a
以上方法都可以实现交换两个数的值,具体选择哪种方法取决于个人偏好和实际情况。