有人可以解释为什么带有整数的示例会导致x和y的值不同,而列表中的示例会导致x和y成为同一个对象吗?
x = 42 y = x x = x + 1 print x # 43 print y # 42 x = [ 1, 2, 3 ] y = x x[0] = 4 print x # [4, 2, 3] print y # [4, 2, 3] x is y # True
python immutability
immutability ×1
python ×1