Computer Science
Which of the following will delete key-value pair for key = "Red" from a dictionary D1 ?
- delete D1("Red")
- del.D1("Red")
- del D1["Red"]
- 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
Which one of the following is correct to insert a single element in a tuple?
- T = 4
- T = (4)
- T = (4, )
- T = [4, ]
Which of the following functions will return key-value pairs of the dictionary?
- key()
- values()
- items()
- get()
What will be the output?
D1 = { "Rahul":56, "Virat":99} print("virat" in D1)- True
- False
- No output
- Error
Which of the following creates a tuple?
- t1 = ("a", "b")
- t1 [2]= ("a", "b")
- t1= (5) *2
- None of these