python built-in integer object
<p>I read an article that python retains some number objects for better performance. For example:</p>

<pre><code>x = 3
y = 3
print(id(x))
print(id(y))
</code></pre>

<p>gives out same values, which means that x and y are referencing to exactly same object. The article suggested that the retained number objects are approximately in range 1~100.</p>

<p>So I tested following code for getting the exact range:</p>

<pre><code>for i in range(-1000,1000):
    x = int(str(i))
    y = int(str(i))
    if str(id(x)) == str(id(y)):
        print(i)
</code></pre>

<p>and the result is quite weird: it prints out -5~256.<br><br>
I'm wondering how these two magic numbers came from and why they're being used. Also, will these two values change in different environment?
Thanks!</p>

<p>256 is a power of two and small enough that people would be using numbers to that range. </p>

<p>-5 I am less sure about, perhaps as special values?</p>

<p>Related: <a href="http://stackoverflow.com/questions/15171695/weird-integer-cache-inside-python">Weird Integer Cache inside Python</a></p>

<p>Also a word of wisdom from that thread:</p>

<blockquote>
  <p>this is an implementation detail, don't ever rely on it happening or not happening</p>
</blockquote>

python