Python Function Reference

id

Get the unique number of an object while the object exists.

Python 3.13
id(object)

Parameters

objectAny
Any object.

Return value

An int.

Examples

Two variables, one object

Python 3.13
a = [1, 2]
b = a
print(id(a) == id(b))
True

Equal but different lists

Python 3.13
a = [1, 2]
c = [1, 2]
print(a == c, id(a) == id(c))
True False

Details

id(a) == id(b) is the same as a is b: it is one and the same object. The number itself changes between runs; objects that exist at different times may get the same number.

See also