निम्नलिखित में से कौन dictionary में कुंजी "tiger" के लिए कुंजी-मूल्य जोड़ी को हटा देगा?
Which of the following will delete the key-value pair for the key "tiger" in the dictionary?
dic = {"lion":"wild", "tiger":"wild", "cat":"domestic", "dog":"domestic"} A
del dic["tiger"]
B
dic["tiger"].delete()
C
delete(dic["tiger"])
D
del(dic["tiger"])
Explanation
The correct answer is (A) del dic["tiger"].
Explanation:
del dic["tiger"]is the correct way to delete the key-value pair for"tiger"from the dictionary.- It removes the key
"tiger"and its associated value from the dictionarydic.
Other options are incorrect:
- (B) dic["tiger"].delete(): There's no
delete()method for dictionary values. - (C) delete(dic["tiger"]): There's no
delete()function in Python for dictionaries. - (D) del(dic["tiger"]): This works but is less common. The more common form is
del dic["tiger"].
So, (A) is the correct choice!
Correct Answer: A) del dic["tiger"]