Pointer or unique id

B

Bruno Desthuilliers

Nomak a écrit :
Hello,

does python have an equivalent to Java: int Object.hashCode() ?

id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects. (Hint: it's the object's memory address.)

hash(obj) -> integer
Return a hash value for the object. Two objects with the same value
have the same hash value. The reverse is not necessarily true, but likely.

HTH
Bruno
 
T

Terry Reedy

Bruno Desthuilliers said:
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects.

This is part of the language specification. Also, the identity of an
object must remain the same for its entire lifetime.
(Hint: it's the object's memory address.)

This is an implementation detail of CPython. It cannot be true if the
garbage collector moves objects around. Or if the object lives elsewhere
(and is accessed thru a proxy).

Terry J. Reedy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top