Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197794
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: Python __hash__ return value - what use is it? |
| Date | Sun, 31 May 2026 09:25:32 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 28 |
| Message-ID | <10vguqb$1ecdn$1@dont-email.me> (permalink) |
| References | <10vgrfu$1dchl$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Sun, 31 May 2026 09:25:32 +0000 (UTC) |
| Injection-Info | dont-email.me; logging-data="1520055"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fjuaJncC3Ij1FFZcNBkuF"; posting-host="cea8d78cbaf754950e95e181f8579758" |
| User-Agent | Pan/0.165 (Kostiantynivka) |
| Cancel-Lock | sha1:jquGwaxW6u6S2CgQncNfkD06d/I= sha256:+vOZ0DkDSIPbCKIVUwL5V5oQoFC6EXESidCWCg586Hg= sha1:tXF1zeHGnYppT6DOaYsrLzbxsw0= |
| Xref | csiph.com comp.lang.python:197794 |
Show key headers only | View raw
On Sun, 31 May 2026 08:28:46 -0000 (UTC), Veek M wrote:
> However when I print the set I see individual instances though I
> want the instances to be the treated the same .ie there should be
> just one instance in the set because the return value from __hash__
> is always 1.
>
> In the dictionary when I print it I see the instances as individual
> keys though I want to see a single key - what gives??
Just tried your code in a Jupyter notebook under Python 3.13.12, and
this was the output:
in __bool__
true
-----
in __hash__
in __hash__
in __eq__ <__main__.MyClass object at 0x7f68a86a4410>
{<__main__.MyClass object at 0x7f68a8691400>}
-----
in __hash__
in __hash__
in __eq__ <__main__.MyClass object at 0x7f68a86a4410>
{<__main__.MyClass object at 0x7f68a8691400>: '20'}
As you expected, only a single element in the set, and only a single
entry in the dict.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python __hash__ return value - what use is it? Veek M <veekjunk@foobar.com> - 2026-05-31 08:28 +0000
Re: Python __hash__ return value - what use is it? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-31 09:25 +0000
Re: Python __hash__ return value - what use is it? Veek M <veekjunk@foobar.com> - 2026-05-31 10:13 +0000
Re: Python __hash__ return value - what use is it? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-05-31 09:40 +0000
Re: Python __hash__ return value - what use is it? Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-05-31 13:06 +0000
csiph-web