Return the id
of an object. This is a unique identifier assigned to every object in Python. The id()
function returns the memory address of the object.
Parameter Values
Parameter | Description |
---|---|
object | an object whose identity is returned |
Return Values
The id()
function in Python always returns a int
representing the object's identity.
How to Use id()
in Python
Example 1:
The id()
function returns the unique identifier of an object in memory.
id(5)
# Output: 140732193753488
Example 2:
When the object is modified, its identifier remains the same as it is based on memory address.
x = [1, 2, 3]
id(x)
# Output: 140732193753232
Example 3:
For different objects, id() returns different identifiers even if the values are the same.
a = 'hello'
b = 'hello'
id(a), id(b)
# Output: (2811710322960, 2811710322960)