Computer Science

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)

Python Dictionaries

4 Likes

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}

Answered By

2 Likes


Related Questions