The storage location of Python integer objects is different. some objects are stored in a certain storage all the time, while others open up the reason for saying this when using them, you can store Python integer objects in different locations. some of them are pre-allocated memory, which is stored in the memory all the time. others open up space during use.
For the reason of this sentence, you can look at the following code:
A = 5b = 5a is B # Truea = 500b = 500a is B # False
The code above shows that integer 5 always exists, while integer 500 never exists.
Which integers are pre-allocated memory addresses?
A, B, c = 0, 0, 0i = 0 while a is B: I + = 1 a, B = int (str (I )), int (str (I) else: print (I) # prints 257
As we know, non-negative integers smaller than or equal to 256 (2 ** 8) are stored all the time (that is, their memory addresses are pre-opened and do not need to be distributed later)
A =-1b =-1a is B # False
Negative numbers are not pre-opened.
The above is a detailed description of the location of integer object storage in Python. For more information, see other related articles in the first PHP community!