What is the name of the function that returns the memory address of an object in CPython?

The story behind the answer

In CPython, the `id()` function returns an integer representing an object’s memory address while that object exists.

Every Python object has an identity, type, and value. The built-in `id()` exposes the identity as an integer, making it useful when investigating whether two variables refer to the same object. In the CPython implementation, that identity integer is the object’s address in memory.

The wording matters: memory-address behavior is a CPython implementation detail, not a universal promise across every Python implementation. Alternative interpreters may represent identity differently while still guaranteeing that an object’s identity remains unchanged during its lifetime. The identifier is also only guaranteed to be unique among simultaneously living objects.

That last point causes a common surprise. After an object is deleted, its memory can be reused, so a later object may receive the same `id()` value. `hash()` serves a different purpose: it produces a hash value for hashable objects, not an identity. `hex()` merely formats an integer in hexadecimal, and `address()` is not a standard Python built-in.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: