The way to exchange two variables in Python is to use automatic tuple packaging and packet.
eg
>>> a=3>>> b=4>>> a,b=b,a>>> print a4>>> print B3 multi-Program language lets you use temporary intermediate variables to swap the values of variables.excerpt from Daniel's introduction: in an assignment, Python requires an expression to the right of the equals sign. What we have written here is B, C, and a is really an expression. To be clear, it is a tuple that has three immutable sequences of elements. Tuples are often enclosed in parentheses, like (b, C, a). But here in addition to the comma there are some other meanings (in a function call), the parentheses are not necessary. Create a tuple with commas by packing each item of a tuple. on the left side of the equal sign of an assignment statement, you can use a single object normally. This object can be a simple notation (known as a variable), an index (such as alist[i] and adict[' Freep '), a reference to a property (such as Anobject.someattribute), and so on. However, Python also lets you use several comma-separated objects (variables, indexes, and so on) to the left of the assignment statement. Such a multi-assignment is also known as unpacking assignment. When there are two or more comma-separated objects on the left side of an assignment statement, the value on the right must be a sequence, and its number is as many as the comma-delimited object on the left. Each item of the sequence is assigned to the corresponding target value from left to right.
Python variable Exchange