[英]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?我知道
v: Tuple
意味着变量 v 必须是 Tuple 类型,但是Tuple[Hashable]
是什么意思呢? Isn't a tuple in Python always hashable? Python 中的元组不是总是可散列的吗?
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.