Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardPythonidentity vs equalitySingle-choice MCQ

A class defines __eq__ but not __hash__. After this, why does putting an instance into a set raise TypeError?

class P: def __init__(self, k): self.k = k def __eq__(self, o): return self.k == o.k s = {P(1)} # TypeError: unhashable type: 'P'