Hacker News new | ask | show | jobs
by deathanatos 3690 days ago
The `is` operator is the same amount of strict in all examples here and in the article: it compares the identities (in CPython, this is essentially the memory address) of two objects.

The reason, in your example, that `is` returns different results is that small integers are "interned"; i.e., the literal 100 always references the exact same integer object, whereas 1000 will cause an integer to be allocated. (So a and b, while both represented 1000, are stored twice in memory.)

1 comments

And in python 3, you can do this manually with sys.intern()
in py2 it's a builtin, so just: intern(thing)