Python unpacks assignment & does not use intermediate variables to exchange the value of variables

concept

The number of left and right variables must correspond to the number of values

a,b,c=10,20,30
print(a,b,c)
>>>10 20 30

significance

When exchanging two variables in other languages, other variables may be needed,
but in python, it can be done by unpacking and assigning

a,b=10,20
a,b=b,a
print(a,b)
>>>20 10

Guess you like

Origin blog.csdn.net/fancynthia/article/details/128852074