Re:Facts and myths about Python names and values
by RodericDay on Sunday July 14, 2013 @12:52PM
(#6041345)
I think two different objects that evaluate to the same thing pass the `==` test, but is checks for identity?
[ Parent
| on HN ]
Re:Facts and myths about Python names and values
by nslocum on Sunday July 14, 2013 @12:55PM
(#6041354)
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
Re:Facts and myths about Python names and values
by audeyisaacs on Sunday July 14, 2013 @02:04PM
(#6041576)
For more details:
http://stackoverflow.com/questions/306313/python-is-operator...
Re:Facts and myths about Python names and values
by nslocum on Sunday July 14, 2013 @02:27PM
(#6041660)
After 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
Re:Facts and myths about Python names and values
by wahnfrieden on Sunday July 14, 2013 @04:43PM
(#6042166)
(CPython)
Re:Facts and myths about Python names and values
by Thrymr on Sunday July 14, 2013 @01:11PM
(#6041402)
> 2 + 4 is 4
True
I sure hope not.