← 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?
- A.remove raises KeyError if x is missing; discard does nothing
- B.discard raises an error if x is missing; remove does nothing
- C.remove deletes all copies; discard deletes one
- 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 →