← Quiz: Magic Methods and Properties: all 10 questions
Quiz: Magic Methods and Properties · Question 10 of 10
Why might objects of a class that defines eq fail to go into a set?
Why might objects of a class that defines __eq__ fail to go into a set?
- A.Sets accept only numbers and strings
- B.Defining eq sets hash to None unless you also define hash
- C.eq makes objects immutable
- D.Sets call lt, which is missing
Answer & explanation
Correct answer: Defining eq sets hash to None unless you also define hash
Sets and dict keys need a hash; define hash for value-like, unchanging objects.
Can you get the rest right without peeking?
Take the timed Quiz: Magic Methods and Properties quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →