➜ /tmp cat t.py
a = 250000000000
b = 250000000000
print id(a), id(b), id(a) == id(b)
➜ /tmp python t.py
140450848587992 140450848587992 True #(Why is True?)
例2:
➜ /tmp python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 250000000000
>>> b = 250000000000
>>> print id(a), id(b), id(a) == id(b)
140443481339400 140443481339208 False #(I think it should be False)
我知道Python有一个小整数缓存池(从 - 5到256),所以两个大整数应该有不同的id。
在Python壳* .py文件运行时,如何解释大整数的不同的行为?
谢谢,现在我知道这个行为完全依赖于实现! – virusdefender