2024-04-20 15:08:55 发布
网友
想知道我们是否可以使用hash()来检查一个对象是否可变?在
>>> from collections.abc import Hashable >>> mutable = [list, bytearray, set, dict] >>> immutable = [int, float, complex, str, tuple, frozenset, bytes] >>> all(isinstance(x(), Hashable) for x in immutable) True >>> any(isinstance(x(), Hashable) for x in mutable) False
所有可变对象都是不可损坏的。在
所有可变对象都是不可损坏的。在
相关问题 更多 >
编程相关推荐