Re:WTFPython: Exploring and understanding Python through sur...
by tekknolagi on Tuesday May 31, 2022 @02:46AM
(#31566742)
CPython does this too (`is` is roughly the same as Java's `==`):
CPython has a small set of canonical objects for integers.
[ Parent
| on HN ]
Re:WTFPython: Exploring and understanding Python through sur...
by bjarneh on Tuesday May 31, 2022 @03:09AM
(#31566868)
Luckily you don't typically compare numbers in Python with 'is'. In Java you should not compare Integer objects with '==' either of course, but '==' is typically used with numbers, and the auto-boxing features of Java makes it very easy to shoot your self in the foot with this stuff.
I once ran into a bug which had been there for years, since some Integer values had never crept over that magic limit, and auto-boxing allowed the numbers to be treated as int's all over, so it really took me some time to figure out what was going on...