Questions and Answers Already Passed
What is the primary purpose of a dictionary in Python?
A) To store data in a sequence
✔✔B) To store key-value pairs
C) To store only unique values
D) To store data in a sorted order
What is the result of calling `len()` on a dictionary?
✔✔A) The number of keys
B) The number of values
C) The total number of key-value pairs
D) An error
How can you retrieve a value from a dictionary using a key?
A) `dict.value(key)`
B) `dict.getvalue(key)`
✔✔C) `dict[key]`
1
,D) `dict.getKey()`
What will happen if you try to access a non-existent key in a dictionary using square brackets?
A) Returns `None`
✔✔B) Raises a `KeyError`
C) Adds the key to the dictionary with a default value
D) Removes all keys
What is the result of `"key" in my_dict` if `"key"` is a key in the dictionary?
✔✔A) True
B) False
C) None
D) Raises an error
What method is used to get all the keys in a dictionary?
A) `dict.getkeys()`
✔✔B) `dict.keys()`
C) `dict.allkeys()`
2
, D) `dict.keylist()`
What will `dict.clear()` do to a dictionary?
A) Remove a specific key-value pair
✔✔B) Remove all key-value pairs
C) Set all values to `None`
D) Create a copy of the dictionary
What is the result of calling `my_dict.items()`?
A) A list of keys
B) A list of values
✔✔C) A view of key-value pairs
D) A sorted list of keys
Which method is used to remove a specific key-value pair from a dictionary?
✔✔A) `pop()`
B) `remove()`
C) `delete()`
3