From the id(object) document :
Return the "identifier" of the object. This is an integer that is guaranteed to be unique and constant for this object throughout its life. Two objects with non-overlapping lifetimes can have the same id () value.
Because the two ranges inside id() calls have non-overlapping lifetimes, their id values may be the same.
The two ranges assigned to the variables have overlapping lifetimes, so they must have different id values.
Edit:
A look at the sources of C shows us builtin_id :
builtin_id(PyObject *self, PyObject *v) { return PyLong_FromVoidPtr(v); }
and PyLong_FromVoidPtr .
PyLong_FromVoidPtr(void *p) { #if SIZEOF_VOID_P <= SIZEOF_LONG return PyLong_FromUnsignedLong((unsigned long)(Py_uintptr_t)p); #else #ifndef HAVE_LONG_LONG # error "PyLong_FromVoidPtr: sizeof(void*) > sizeof(long), but no long long" #endif #if SIZEOF_LONG_LONG < SIZEOF_VOID_P # error "PyLong_FromVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)" #endif return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(Py_uintptr_t)p); #endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ }
Thus, the identifier is a memory address.
user1907906
source share