7 ms·
You're correct. Further, there are some odd quirks because of the way Python caches small Integers for efficiency. > 2 + 2 is 4 True > 1000 + 1 is 1001
by nslocum 13y ago
You're correct.
Further, there are some odd quirks because of the way Python caches small Integers for efficiency.
> 2 + 2 is 4
True
> 1000 + 1 is 1001
False
- Thrymr 13y ago> 2 + 4 is 4 True I sure hope not.
- nslocum 13y agolol, thanks, i fixed it
- alecrn 13y ago(I think you meant 2 + 2 is 4)
- audeyisaacs 13y agoFor more details: http://stackoverflow.com/questions/306313/python-is-operator-behaves-unexpectedly-with-integers http://stackoverflow.com/questions/306313/python-is-operator...
- nslocum 13y agoAfter a little trial and error, it appears that Python caches the values in range(-5,257). > -6 + 0 is -6 False > -5 + 0 is -5 True > 256 + 0 is 256 True > 257 + 0 is 257 False
- wahnfrieden 13y ago(CPython)