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. D1.del["Red"]

Python Dictionaries

3 Likes

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

3 Likes


Related Questions