CBSE Class 11 Computer Science Question 42 of 112

Dictionaries — Question 22

Back to all questions
22
Question

Question 22

Which of the following Python codes will give the same output if

dict = {"diary":1, "book":3, "novel":5}

(i) dict.pop("book")
(ii) del dict["book"]
(iii) dict.update({"diary":1,"novel":5})

  1. (i), (ii), (iii)
  2. (1), (ii)
  3. (i), (iii)
  4. (ii), (iii)
Answer

(i), (ii)

Reason — Expression dict.pop("book") and del dict["book"] will give same output as both of them are removing the key "book" from dict i.e., {'diary': 1, 'novel': 5}