🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Sets accept only numbers and strings
  2. B.Defining eq sets hash to None unless you also define hash
  3. C.eq makes objects immutable
  4. 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 →