KnowledgeBoat Logo
|

Computer Science

Which of the following will delete key-value pair for key = "Red" from a dictionary D1 ?

  1. delete D1("Red")
  2. del.D1("Red")
  3. del D1["Red"]
  4. del D1

Python Dictionaries

1 Like

Answer

del D1["Red"]

Reason — The syntax to delete a key-value pair from a dictionary in Python is : del dictionary_name[key]. Therefore, according to this syntax, del D1["Red"] is correct statement.

Answered By

2 Likes


Related Questions