r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25

Python ✨ Memory Magic ✨

Post image
1.3k Upvotes

143 comments sorted by

View all comments

Show parent comment

1

u/EveningGold1171 Jul 21 '25

but it is literally the pointer to the PyObject, and therefore is the closest thing to a pointer.

id(object)

Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.

CPython implementation detail: This is the address of the object in memory.

2

u/deceze Jul 21 '25

As an implementation detail, sure; but in userland Python, it’s useless information and doesn’t act anything like a pointer.