简体   繁体   中英

float, tuple and frozenset are all hashable, why frozenset is special

In Python3.7.4

When I test to run this:

>>> hash((1.000001))
2305843009025
>>> hash(1.000001)
2305843009025
>>> (1.000001) == 1.000001
True
>>> [1.000001] == 1.000001
False

But why:

>>> frozenset({1.000001}) == 1.000001
False
>>> hash(frozenset({1.000001}))
8757482414179413028

float, tuple and frozenset are all hashable, why frozenset is special

I made a mistake. The comma is the identity of the tuple.

>>> hash(frozenset({1.000001}))
8757482414179413028
>>> hash((1.000001,))
2305846529543933606
>>> hash((1.000001))
2305843009025
>>> hash(1.000001)
2305843009025
>>> type((1.000001))
<class 'float'>
>>> type(1.000001)
<class 'float'>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM