Lesson 7
Objects and Dictionaries
Chapter 2: Object Identity
Object identity
A Python object will have an ‘identity’ (unique integer) assigned to it throughout its lifetime (i.e. when it exists in memory after you run your program). It acts as a unique ID for the object.
For the official Python interpreter, the identity will be the address of the object in memory.
You can obtain an object’s identity with the id()
function.
>>> x = 9000
>>> y = "python"
>>> id(x)
140613670158160
>>> id(y)
140613671017648
If two variables result in the same id
, it means that they both refer to the same object.
>>> x = 9000
>>> y = x
>>> id(x)
140613670158096
>>> id(y)
140613670158096