慕桂英4014372
任何不可变的东西(可变的意思,可能会改变)都可以进行哈希处理。除了要查找的哈希函数,如果一个类有它,例如。dir(tuple)并寻找__hash__方法,这里有一些例子#x = hash(set([1,2])) #set unhashablex = hash(frozenset([1,2])) #hashable#x = hash(([1,2], [2,3])) #tuple of mutable objects, unhashablex = hash((1,2,3)) #tuple of immutable objects, hashable#x = hash()#x = hash({1,2}) #list of mutable objects, unhashable#x = hash([1,2,3]) #list of immutable objects, unhashable不可变类型列表:int, float, decimal, complex, bool, string, tuple, range, frozenset, bytes可变类型列表:list, dict, set, bytearray, user-defined classes