Dictionary Keys Method
Which method returns a list of all keys in a Python dictionary?
- all_keys()
- keys()
- getKeyList()
- listKeys()
- KeyList()
Dictionary Mutability
Are Python dictionaries mutable objects, allowing for changes after creation?
- No, dictionaries are immutable.
- Only the keys are mutable.
- Only the values are mutable.
- Yes, dictionaries are mutable.
- Dictionaries are mutable, but only when initially defined.
Dictionary Length
Which function can be used to determine the number of key-value pairs in a dictionary?
- size()
- length()
- count()
- len()
- sizeof()
Dictionary Item Removal
Which method removes and returns an arbitrary key-value pair from a dictionary?
- remove()
- delete()
- pop()
- popitem()
- clear()
Dictionary Clearing
What method removes all items from a dictionary, leaving it empty?
- remove_all()
- flush()
- clear()
- empty()
- removeAll()
Nested Dictionaries
How can you access a value within a nested dictionary, assuming the structure is two levels deep?
- dict[key1, key2]
- dict.key1.key2
- dict[key1][key2]
- dict.get(key1, key2)
- dict(key1, key2)
Sorting Dictionaries
What function should be used to sort a dictionary?
- order()
- sort()
- sorted()
- arrange()
- reorder()
Dictionary Views Method
Which method returns a list consisting of key and value tuples?
- tuple()
- pairs()
- lists()
- items()
- dictionaryitems()
Dictionary Existence Check
How can you check if a specific key exists in a dictionary?
- Using a try-except block with KeyError
- Using the 'exists' keyword
- Using the 'contains' method
- Using the 'if' statement with the 'in' operator
- Using the 'has_key' method
Merging Dictionaries
What operator, available in Python 3.9 and later, can be used to merge two dictionaries?
- +
- *
- |
- u0026
- ^