What does the get() method do in a dictionary?
It retrieves the value for a specified key, returning None if the key is not found.
Define keys() method.
Returns a view object displaying a list of all the keys in the dictionary.
What does the values() method return?
It returns a view object displaying a list of all the values in the dictionary.
Fill in the blank: The items() method returns _______.
A view object of key-value pairs in the dictionary.
True or false: The update() method adds key-value pairs to a dictionary.
TRUE
It can also update existing keys with new values.
What does the pop() method do?
Removes and returns the value associated with a specified key.
Define popitem() method.
Removes and returns the last inserted key-value pair as a tuple.
What is the purpose of the clear() method?
It removes all items from the dictionary.
Fill in the blank: The setdefault() method returns the value of a key, and if not present, it sets it to _______.
A default value.
True or false: The copy() method creates a shallow copy of the dictionary.
TRUE
Changes to the copy do not affect the original dictionary.
What does the fromkeys() method do?
Creates a new dictionary with specified keys and a default value.
Define del statement in the context of dictionaries.
It removes a specified key and its associated value from the dictionary.
What is the result of using len() on a dictionary?
It returns the number of key-value pairs in the dictionary.
Fill in the blank: The in keyword checks if a key is _______ in a dictionary.
Present.
True or false: Dictionary keys can be mutable types.
FALSE
Only immutable types like strings, numbers, and tuples can be keys.
What does the dict() constructor do?
Creates a new dictionary from an iterable or keyword arguments.
Define dict comprehension.
A concise way to create dictionaries using a single line of code.
What is the purpose of the update() method?
It merges another dictionary or iterable of key-value pairs into the current dictionary.
Fill in the blank: The get() method can take a second argument as a _______.
Default value.
True or false: Dictionary values can be of any data type.
TRUE
Values can be strings, lists, dictionaries, etc.
What does the view() method return?
It returns a view object that displays a dynamic view of the dictionary’s entries.
Define nested dictionaries.
Dictionaries that contain other dictionaries as values.
What is the output of d.get(‘key’, ‘default’) if ‘key’ is not in d?
It returns ‘default’.
Fill in the blank: The keys() method returns a _______ object.
View.