To explain better, I wrote a small class node
, and set a
and b
:
class node(object):
def __init__(self,x,y):
self.val = x
self.next = y
a = node(5,6)
b = None
Then I found the result is different between:
a, a.next, b = a.next, b, a
print(a,b) #it returns AttributeError: 'int' object has no attribute 'next'
and:
a.next, a, b = b, a.next, a
print(a,b) #it returns 6 <__main__.node object at 0x1021a0400>
We all know, when a, b = b, a+b
, it gives a,b value simultaneously, and the result doesn't change when the code becomes b, a = a+b, b
.
So, could anybody help me with it? Why does this happen?