What happens to my python variable? old_posseems to be related to pos:
the code:
pos = [7, 7]
direction = [1, 1]
old_pos = pos
print 'pos = '+str(pos)
print 'old_pos = '+str(old_pos)
pos[0] += direction[0]
pos[1] += direction[1]
print 'pos = '+str(pos)
print 'old_pos = '+str(old_pos)
Conclusion:
pos = [7, 7]
old_pos = [7, 7]
pos = [8, 8]
old_pos = [8, 8]
However, if I replaced old_pos = poswith old_pos = tuple(pos)or even old_pos = list(pos), I will not get this problem:
pos = [7, 7]
old_pos = [7, 7]
pos = [8, 8]
old_pos = [7, 7]
source
share