+ 1
Python variable swapping
Consider this code snippets: a = 5 b = 4 a, b = b, a In this code, why isn't b equal to the new, modified value of a (i.e., b itself), and instead holds the old value of a? What exactly happens when doing this? Does Python create a copy of the variables in the right-hand side, and use the new copy holding the old values to assign the variables in the left-hand side?
3 ответов
+ 1
On the right side in the 3rd line a tuple is created which has its own memory address.
0
Runtime Terror and Lisa Thank you very much. Is this also applicable to objects?