File I/O in Python
15 questions · 12 min · Medium
Test your knowledge of Python dictionaries, including creation, accessing values, updating items, dictionary methods, iteration, and nested dictionaries.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. dict
Python dictionaries are instances of the built-in dict type.
B. {}
Curly braces are used to create dictionary literals, such as {"name": "John"}.
A. {"name": "Alice", "age": 25}
A dictionary contains key-value pairs separated by colons and separated from each other by commas.
B. person["name"]
Dictionary values can be accessed using square brackets with the corresponding key.
C. It raises a KeyError
Accessing a missing key with dictionary[key] raises a KeyError.
B. get()
The get() method returns the value for a key and can return a default value if the key does not exist.
A. person["age"] = 30
Assigning a value to a key adds the key if it is new or updates the existing value if the key already exists.
A. keys()
The keys() method returns a view containing the dictionary's keys.
A. values()
The values() method returns a view containing the dictionary's values.
B. items()
The items() method returns a view of the dictionary's key-value pairs.
C. pop()
The pop() method removes the specified key and returns its associated value.
B. clear()
The clear() method removes all key-value pairs from the dictionary.
A. in
The in operator checks whether a specified key exists in a dictionary.
B. 2
The key "b" is associated with the value 2, so data["b"] returns 2.
A. Dictionary keys must be unique
Each key in a dictionary is unique. Assigning a new value to an existing key replaces its previous value.