I can understand the following definition:
Every object has an identity, a type and a value. An object's identity never changes once it has been created; you may think of it as the object’s address in memory. The
is
operator compares the identity of two objects; theid()
function returns an integer representing its identity.
I would assume the above definition works when “something” is created, such as:
>>> a = 0
>>> id(a)
1720438480
But I do not understand:
>>> id(1)
1720438512
>>> b = 1
>>> id(b)
1720438512
I did not create anything yet; so how can the integer “1” have an ID? Does it mean that as soon as I “mention” 1 in the Python Shell, it is assigned to a memory address? Also, does it mean that because the ID never changes during its lifetime, and because my computer has a limited memory, if I repeatedly ask for the id() of unique things, I will eventually get something like “out of memory” message? (It cannot reallocate memory, because the lifetime of others have not ended yet.)
Or, showing my ear from the other way round:
>>> id(something_1)
some unique memory address
>>> id(something_2)
some unique memory address
>>> ...
At which point is the memory reallocated? That is, at which point,
>>> my_variable = something_1
>>> id(my_variable)
will give an ID that is different from id(something_1)
?