简体   繁体   中英

What does Tuple[Hashable] mean in Python?

I came across the following piece of code:

def func(self, v: Tuple[Hashable]):
...

I know v: Tuple would mean variable v must be of type Tuple, but what does Tuple[Hashable] mean? Isn't a tuple in Python always hashable?

A tuple is only hashable if the values in the tuple are hashable themselves.

>>> hash((1,2))
-3550055125485641917
>>> hash(([1],2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

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