I tested following in Windows 7 cmd:
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 8
>>> b = 8
>>> id(a)
8791373558832
>>> id(b)
8791373558832
>>> a is b
True
>>> c = -8
>>> d = -8
>>> id(c)
4802576
>>> id(d)
5223952
>>> c is d
False
>>> type(a)
<class 'int'>
>>> type(c)
<class 'int'>
>>>
Objects a, b, c, d are all of type int, I used to think the objects of the same type should be processed in the same way in memory allocation. I have search The Python Standard Library documentation but find nothing relative to this.
Could any one help to explain?