4 ms·
I meant related in the strictness of the is operator.
by pdknsk 10y ago
I meant related in the strictness of the is operator.
- deathanatos 10y agoThe `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.)