By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,050 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,050 IT Pros & Developers. It's quick & easy.

Pointer or unique id

P: n/a
Hello,

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

TIA
--
Nomak
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a
Bruno Desthuilliers wrote:
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.


Of course not all Python objects are hashable:
hash([])

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: list objects are unhashable
--
Michael Hoffman
Jul 18 '05 #3

P: n/a

"Bruno Desthuilliers" <bd*****************@free.quelquepart.fr> wrote in
message news:41***********************@news.free.fr...
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

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.