Nomak a écrit :[color=blue]
> Hello,
>
> does python have an equivalent to Java: int Object.hashCode () ?
>[/color]
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.
Bruno Desthuilliers wrote:
[color=blue]
> 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.[/color]
Of course not all Python objects are hashable:
[color=blue][color=green][color=darkred]
>>> hash([])[/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: list objects are unhashable
--
Michael Hoffman
"Bruno Desthuilliers" <bdesth.quelque chose@free.quel quepart.fr> wrote in
message news:41e94d40$0 $29202$636a15ce @news.free.fr.. .[color=blue]
>id(object) -> integer
>Return the identity of an object. This is guaranteed to be unique among
>simultaneous ly existing objects.[/color]
This is part of the language specification. Also, the identity of an
object must remain the same for its entire lifetime.
[color=blue]
> (Hint: it's the object's memory address.)[/color]
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).
Comment