>>> lis = [5,6,7,10,11,12] >>> lis[0], lis[-1] = lis[-1], lis[0] >>> lis [12, 6, 7, 10, 11, 5]
The procedure for evaluating the above expression:
expr3, expr4 = expr1, expr2
The first elements in the RHS are assembled in a tuple, and then the tuple is unpacked and assigned to the LHS elements.
>>> lis = [5,6,7,10,11,12] >>> tup = lis[-1], lis[0] >>> tup (12, 5) >>> lis[0], lis[-1] = tup >>> lis [12, 6, 7, 10, 11, 5]
source share