Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 21 of 102
Marks: +1, -0
Which of the following is true about clear() in Python ?
[CBSE 2026 Compartment]
Solution:  
Concept:
D.clear() is a dictionary method that removes all key-value pairs; the dictionary object still exists and becomes {}.
Explanation:
D = {'a': 1, 'b': 2}
D.clear()
print(D) # {}
(A) Deleting the dictionary itself is done by del D, not clear().
(C) clear() is a method, called as D.clear(); clear(D) gives a NameError.
(D) The method does exist.
Answer:
Option B (It deletes all items of the dictionary resulting in an empty dictionary.)
© examsnet.com
Advertisements
Go to Question: