Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Function

id

id() returns an integer identity for an object. It remains unique and constant during that object's lifetime, but values may be reused by objects whose lifetimes do not overlap.

How it works

Call id() with one object to obtain its identity as an integer. That value remains constant and unique for that object during its lifetime, although a later object may receive the same value after the original object no longer exists.

Syntax

id(object, /)

Parameters

NameTypeDescription
objectobjectThe object whose identity is returned.

Returns

An integer representing the object's identity, guaranteed unique and constant during that object's lifetime.

Key points

  • The function reports an object's identity.
  • Its result is an integer that stays constant and unique for the object while that object exists.
  • Identity values can be reused when objects do not exist at the same time.
  • A call emits the documented builtins.id auditing event.

Common mistakes

  • Do not treat an identity value as globally unique forever; values can be reused after an object's lifetime ends.

Example: Check an object's identity

value = []
print(id(value) == id(value))

The same object produces the same identity value while it remains alive.

When to use it

Check whether two references point to the same object

Debugging references

Track an object during its lifetime

Object lifecycle diagnostics

Observe calls through Python's auditing mechanism

Auditing

Interview questions

QWhat does id() return?

id() accepts one object and returns an integer representing that object's identity. The value is guaranteed to stay constant and be unique for that object while the object is alive.

Follow-up: Can two different objects have the same identity value? Yes, if their lifetimes do not overlap, because the value may be reused.

QHow is identity different from equality?

The result identifies the object itself, not merely an equal value. Two separate objects can compare equal while still having different identities.

Follow-up: How would you test object identity directly? Use the is operator when checking whether two references point to the same object.

QDoes calling id() have any observable interpreter behavior besides returning an integer?

The function raises the builtins.id auditing event with the supplied object as its argument. This lets auditing mechanisms observe calls to the built-in.

Follow-up: What should code use for ordinary object identity checks? Prefer is; use id() when an integer identity representation is specifically needed.

  • is
  • object
  • type
  • hash

Source: Built-in Functions — Python 3.16.0a0 documentation. Checked 2026-10-15.