What is the purpose of the clear() method for dictionaries?
A. Removes all key-value pairs from the dictionary
B. Adds a key-value pair to the dictionary
C. Removes the last key-value pair
D. Deletes the dictionary
Answer: Option A
A. Removes all key-value pairs from the dictionary
B. Adds a key-value pair to the dictionary
C. Removes the last key-value pair
D. Deletes the dictionary
Answer: Option A
Which of the following data types in Python is used to store key-value pairs?
A. Dictionary
B. List
C. Tuple
D. Set
A. setdefault()
B. addkey()
C. insert()
D. newkey()
What does the len() function do when applied to a dictionary?
A. Returns the number of key-value pairs in the dictionary
B. Returns the sum of all values
C. Returns the length of the longest key
D. Returns the length of the longest value
In Python, how can you get a list of all key-value pairs in a dictionary?
A. items()
B. get_items()
C. all_items()
D. list_items()
Join The Discussion