Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

id()

Returns an integer identifying an object during its lifetime.

Version: Python 3.14; repository image, production runtime not attested

Syntax

id(object, /)

Returns an integer identifying an object during its lifetime.

Aliases share an identity. Distinct simultaneously live lists have different identities even when their contents compare equal.

Identity is constant and unique among objects alive at the same time. The alias and left refer to one list and therefore have the same id. A separately allocated equal list has a different id while both exist. After an object dies its integer identifier can be reused; avoid treating it as a permanent identifier.

a = [3]
b = a
c = [3]
assert a == c and id(a) == id(b) and id(a) != id(c)

Examples

left = [3]
alias = left
right = [3]
print(id(left) == id(alias))
print(id(left) == id(right))

Result

True
False

Identity is constant and unique among objects alive at the same time. The alias and left refer to one list and therefore have the same id. A separately allocated equal list has a different id while both exist. After an object dies its integer identifier can be reused; avoid treating it as a permanent identifier.

Sources