The return value of the ID method is the memory address of the object.
Python allocates memory for each object that appears, even if their values are exactly equal (note that equality is not the same). If you execute a=2.0,b=2.0 these two statements will allocate memory for 2.0 of this type of float object, and then point A and B respectively to the two objects. So A and B are not pointing to the same object:
>>> a=2.0
>>> b=2.0
>>> A is B
False
>>> a==b
True
But in order to improve the efficiency of memory for some simple objects, such as some of the smaller int objects, Python takes the method of reusing object memory , such as pointing to a=2,b=2, because 2 is a simple int type and the value is small, Python does not allocate memory two times. Instead, assign a and B to the assigned object at the same time:
>>> a=2
>>> b=2
>>> A is B
True
If you do not assign a value of 2 instead of a large value, the situation is the same as before:
>>> a=5555
>>> b=5555
>>> A is B
False
>>> ID (a)
12464372
>>> ID (b)
12464396
Reference:
1, https://www.cnblogs.com/dplearning/p/5998112.html
Python's knowledge of how to allocate memory for different objects