Built-in Functions and Types

id()

Obtain an integer identifying an object for its lifetime. Two simultaneously existing objects have different IDs; a later object can reuse the ID of an earlier destroyed object. CPython uses the memory address as the ID, but portable Python code must not depend on that representation. Compare identities with is instead of comparing IDs when possible. IDs are not persistent database keys.

Formal Syntax & Structure

python syntaxpython
id(object, /)

Parameters & Attributes

NameTypeDescription
objectobjectLive object to identify.

Return Value

int

Identity token unique during the lifetime of the object.

Working Example

Example Snippetpython
first = [1]alias = firstsecond = [1]print(id(first) == id(alias))print(id(first) == id(second))print(first == second)
Python Reference