5 ms·
Mutable objects can't be hashed right?
by abhishekjha 7y ago
Mutable objects can't be hashed right?
- detaro 7y agoAs the comment you responded to says: An object can be mutable and hashable. E.g. any custom class by default has mutable and hashable instances.
- abhishekjha 7y agoHow can you get both mutable and hashable instances at the same time?
- detaro 7y agothe only requirement on a hashable instance is that it implements a proper __hash__ function. The default implementation in CPython returns the address of the memory the object is stored at, so all instances are considered unique, values play no role at all.