🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Tuples and Sets: all 15 questions

Quiz: Tuples and Sets · Question 14 of 15

What is the difference between s.remove(x) and s.discard(x) for a set s?

What is the difference between s.remove(x) and s.discard(x) for a set s?

  1. A.remove raises KeyError if x is missing; discard does nothing
  2. B.discard raises an error if x is missing; remove does nothing
  3. C.remove deletes all copies; discard deletes one
  4. D.There is no difference
Answer & explanation

Correct answer: remove raises KeyError if x is missing; discard does nothing

Use discard when the item may or may not be in the set.

Can you get the rest right without peeking?

Take the timed Quiz: Tuples and Sets quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →