【发布时间】:2012-11-24 07:24:36
【问题描述】:
>>>a=[999999,2,3]
>>>b=[999999,2,3]
>>>print(a[0] is b[0])
False#because it works for numbers -5 through 256
>>>a=[1,2,3]
>>>b=a[:]
>>>print(a[0] is b[0])
True#because it works for numbers -5 through 256
>>>a=[999999,2,3]
>>>b=a[:]
>>>print(a[0] is b[0])
True#why not False ???
发生了什么 b=a[:] (为什么不适用于数字 -5 到 256 )?
【问题讨论】:
-
我认为你混淆了两件奇怪的事情:1)
b=a[:]复制对所有整数的引用,所以b[0]指向与a[0]相同的 int 并且a[0] is b[0]返回 @ 987654326@。 2) 始终保留对数字 -5 到 256 的引用。
标签: python python-3.x python-2.7