(NEW 2026/2027 UPDATE) PYTHON FOR IT
AUTOMATION, WITH CORRECT ANSWERS &
DETAILED RATIONALES
WGU D522 OBJECTIVE ASSESSMENT:
PYTHON FOR IT AUTOMATION
1. What is the primary advantage of using dictionaries in Python?
A. They store values in order
B. They allow fast numerical indexing
C. They associate values with descriptive keys
D. They hold only unique items
✅ Correct Answer: C
Rationale: Dictionaries map descriptive keys to values, allowing expressive data relationships.
2. Which code snippet demonstrates the creation of a dictionary with key-value pairs?
A. devices = ('Router1', '192.168.1.2')
B. devices = ['Router1': '192.168.1.2']
C. devices = {'Router1': '192.168.1.2', 'Switch2': '10.0.0.2'}
D. devices = dict('Router1','192.168.1.2')
✅ Correct Answer: C
Rationale: Curly braces with key:value syntax define a Python dictionary.
3. Which snippet correctly creates a dictionary with various data types for keys and
values?
A. data_types = {'string_key': [1,2,3], (4,5,6): 'tuple_key'}
B. data_types = [string_key=1,2,3]
,C. data_types = dict(string_key=[1,2,3], 'tuple_key')
D. data_types = set('string_key', [1,2,3])
✅ Correct Answer: A
Rationale: Dictionaries can use tuples as keys and lists as values; option A follows valid syntax.
4. Which demonstrates using dict() to create a dictionary?
A. dl = dict(key1='value1')
B. dl = dict('key1','value1')
C. dl = dict([('key1','value1'),('key2','value2')])
D. dl = dict{'key1':'value1'}
✅ Correct Answer: C
Rationale: dict() can accept a list of key–value tuple pairs.
5. How do you access an item in a dictionary using its key?
A. dict2.get("keyA")
B. dict2["keyA"]
C. Both A and B
D. dict2.keyA
✅ Correct Answer: C
Rationale: You may retrieve a value by square brackets or by using .get().
6. How do you change the value of a key in a dictionary?
A. devices.add("DeviceA"="192.168.1.100")
B. devices["DeviceA"] = "192.168.1.100"
C. replace(devices, DeviceA, 192.168.1.100)
D. devices.update_key()
✅ Correct Answer: B
Rationale: Assigning to a key replaces its previous value.
7. Which snippet shows the use of update()?
A. info1.add(info2)
B. info1.merge(info2)
, C. info1.update(info2)
D. update(info1, info2)
✅ Correct Answer: C
Rationale: update() merges another dictionary into the current dictionary.
8. How do you add a new item to a dictionary?
A. dict.add(key, value)
B. dict.push(key, value)
C. Assign a value to a new key
D. Use insert()
✅ Correct Answer: C
Rationale: Simply assigning a value to a new key adds it to the dictionary.
9. Which snippet removes an item from a dictionary?
A. dict3.remove("keyX")
B. rm dict3["keyX"]
C. del dict3["keyX"]
D. dict3.delete(keyX)
✅ Correct Answer: C
Rationale: del dict[key] removes the key and its corresponding value.
10. What does clear() do in a dictionary?
A. Deletes the dictionary entirely
B. Removes all items
C. Removes the last item only
D. Removes keys but not values
✅ Correct Answer: B
Rationale: clear() empties the dictionary but leaves it existing.
11. Which snippet correctly uses a set to hold unique items?
A. devices = ['Switch','Router','Firewall']
B. devices = ('Switch','Router','Firewall')