1. Home
  2. Data Science
  3. Python
  4. What is the difference between remove() and discard() on a…

Added 25 Nov 2026

What is the difference between remove() and discard() on a set in Python?

  1. discard() raises KeyError if missing; remove() does not
  2. remove() raises KeyError if missing; discard() does not Correct answer
  3. They are identical
  4. remove() deletes all copies

Correct answer

B. remove() raises KeyError if missing; discard() does not

6 views

MCQSEXAM

Explanation

discard() silently ignores missing elements.

Reference

Asked in: Python Interview Sets

https://docs.python.org/3/tutorial/datastructures.html#sets

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs