In python
>>> a = 5
>>> a is 5
True
but
>>> a = 500
>>> a is 500
False
This is because it stores low integers as a single address. But once the numbers begin to be complex, each int gets its own unique address space. This makes sense to me.
The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object.
So now, why does this not apply to strings? Are not strings just as complex as large integers (if not moreso)?
>>> a = '1234567'
>>> a is '1234567'
True
How does python use the same address for all string literals efficiently? It cant keep an array of every possible string like it does for numbers.