Variables in Python are just pointers, as far as I know.
Based on this rule, I can assume that the result for this code snippet:
i = 5
j = i
j = 3
print(i)
would be 3
.
But I got an unexpected result for me, it was 5
.
Moreover, my Python book does cover this example:
i = [1,2,3]
j = i
i[0] = 5
print(j)
the result would be [5,2,3]
.
What am I understanding wrong?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…