➜ /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