Python for IT Automation | Qs & As| Grade A| 100%
Correct (Verified Answers)
INTRODUCTION
This comprehensive study guide features verified multiple-choice
questions covering the most frequently tested topics on the WGU D522
Objective Assessment for Python for IT Automation, including dictionaries,
sets, lists, tuples, loops, functions, file handling, error handling, and
automation scripting. Each question is paired with the correct answer in
bold italics and a detailed rationale explaining the underlying Python
programming concepts. Based on the latest 2025/2026 examination
standards and the WGU D522 curriculum, this resource is designed for IT
students preparing for the Python for IT Automation Objective
Assessment.
SECTION 1: PYTHON DICTIONARIES
Question 1
What is the primary advantage of using dictionaries in Python?
,A) They allow you to associate values with descriptive keys, providing a
convenient way to represent relationships between data
B) They are faster than lists
C) They use less memory
D) They are easier to sort
Answer: A) They allow you to associate values with descriptive keys,
providing a convenient way to represent relationships between data
Explanation: Dictionaries allow you to associate values with descriptive
keys, providing a convenient way to represent relationships between data
.**
Question 2
Which Python code snippet correctly demonstrates the creation of a
dictionary with key-value pairs?
A) devices = {'Router1': '192.168.1.2', 'Switch2': '10.0.0.2'}
B) devices = ['Router1', '192.168.1.2', 'Switch2', '10.0.0.2']
C) devices = ('Router1', '192.168.1.2', 'Switch2', '10.0.0.2')
D) devices = {'Router1', '192.168.1.2', 'Switch2', '10.0.0.2'}
Answer: A) devices = {'Router1': '192.168.1.2', 'Switch2': '10.0.0.2'}
Explanation: Dictionaries are created using curly braces {} with key-
value pairs separated by colons. This is the correct syntax for creating a
dictionary .**
,Question 3
Which Python code snippet correctly demonstrates the creation of a
dictionary with various data types for both keys and values?
A) data_types = {'string_key': [1, 2, 3], (4, 5, 6): 'tuple_key'}
B) data_types = ['string_key', [1, 2, 3], (4, 5, 6), 'tuple_key']
C) data_types = ('string_key', [1, 2, 3], (4, 5, 6), 'tuple_key')
D) data_types = {'string_key', [1, 2, 3], (4, 5, 6), 'tuple_key'}
Answer: A) data_types = {'string_key': [1, 2, 3], (4, 5, 6): 'tuple_key'}
Explanation: This demonstrates a dictionary with various data types for
both keys and values. Keys must be immutable (strings, tuples, numbers)
and values can be any data type .**
Question 4
Which Python code snippet correctly demonstrates the use of the
dictionary constructor, dict()?
A) d = dict([('key1', 'value1'), ('key2', 'value2')])
B) d = dict('key1', 'value1', 'key2', 'value2')
C) d = dict['key1', 'value1', 'key2', 'value2']
D) d = dict{'key1': 'value1', 'key2': 'value2'}
Answer: A) d = dict([('key1', 'value1'), ('key2', 'value2')])
, Explanation: The dict() constructor can take a list of tuples as an
argument to create a dictionary .**
Question 5
Which Python code snippet correctly demonstrates how to access an item
in a dictionary using its key?
A) dict2 = {"keyA": "valueA", "keyB": "valueB"}; value = dict2["keyA"]
B) dict2 = {"keyA": "valueA", "keyB": "valueB"}; value = dict2.keyA
C) dict2 = {"keyA": "valueA", "keyB": "valueB"}; value = dict2(0)
D) dict2 = {"keyA": "valueA", "keyB": "valueB"}; value = dict2.get[0]
Answer: A) dict2 = {"keyA": "valueA", "keyB": "valueB"}; value =
dict2["keyA"]
Explanation: Dictionary items are accessed using square brackets with
the key name .**
Question 6
Which Python code snippet correctly demonstrates how to change the
value of a specific key in a dictionary?
A) devices = {"DeviceA": "192.168.1.1", "DeviceB": "10.0.0.1"};
devices["DeviceA"] = "192.168.1.100"
B) devices = {"DeviceA": "192.168.1.1", "DeviceB": "10.0.0.1"};
devices.DeviceA = "192.168.1.100"