WGU D522 Python for IT Automation
Objective Assessment | OA V1 and V2 |
Questions and Answers | 2026/27 Update
| 100% Correct.
Section 1: Python Fundamentals & Data Types (Questions 1-12)
Q1: Which Python collection is best suited for storing an ordered sequence of elements that can be
modified?
a) Tuple
b) Set
c) List
d) Dictionary
Correct Answer: c) List
Rationale: Lists are ordered, mutable (changeable) collections. Tuples are immutable, sets are
unordered, and dictionaries store key-value pairs. Lists are ideal for tasks requiring ordered, changeable
data, such as maintaining a sequence of server names in an IT automation script.
Q2: Which data structure is ordered but immutable (cannot be modified once created)?
a) List
b) Tuple
c) Set
d) Dictionary
Correct Answer: b) Tuple
,Rationale: Tuples maintain order but cannot be modified after creation. They are used for fixed,
permanent data like coordinates or configuration constants. This immutability makes tuples hashable,
allowing them to be used as dictionary keys.
Q3: Which data structure stores unique, unordered items and automatically eliminates duplicates?
a) List
b) Tuple
c) Set
d) Dictionary
Correct Answer: c) Set
Rationale: Sets do not preserve order and automatically eliminate duplicates. They are excellent for
membership testing and filtering unique values, such as extracting unique IP addresses from log files.
Sets use hash-based lookup for O(1) membership testing.
Q4: Which data structure stores data as key-value pairs, allowing fast lookup by a descriptive key?
a) List
b) Tuple
c) Set
d) Dictionary
Correct Answer: d) Dictionary
Rationale: Dictionaries store data as key-value pairs, allowing data to be accessed using meaningful
labels rather than numeric indexes. They are ideal for representing relationships such as device names
and IP addresses. Dictionaries provide O(1) average-time complexity for lookups.
Q5: Which Python module is primarily used for interacting with the operating system (e.g., creating
directories, checking paths)?
a) sys
b) os
, c) requests
d) json
Correct Answer: b) os
Rationale: The os module provides functions for interacting with the operating system, such
as os.mkdir(), os.path.exists(), and os.getcwd(). The sys module handles system-specific
parameters, requests is for HTTP, and json is for data formatting.
Q6: What is the correct syntax to define a function in Python?
a) function my_func():
b) def my_func():
c) define my_func():
d) func my_func():
Correct Answer: b) def my_func():
Rationale: Python uses the def keyword to define functions. The syntax is def
function_name(parameters):. The colon at the end is required, and the function body must be indented.
Q7: Which method is used to read the entire content of a file into a string?
a) file.read()
b) file.readline()
c) file.readlines()
d) file.get()
Correct Answer: a) file.read()
Rationale: read() reads the entire file content as a single string. readline() reads one line at a time,
and readlines() reads all lines into a list of strings. For large files, consider reading in chunks to manage
memory.
Q8: What does the subprocess.run() function do?
, a) Runs a Python script in a new thread
b) Executes a system command and waits for it to complete
c) Runs a function asynchronously
d) Installs a Python package
Correct Answer: b) Executes a system command and waits for it to complete
Rationale: subprocess.run() is used to run system commands (like ping or dir) from within a Python
script and waits for the command to finish. It returns a CompletedProcess instance containing the
command's output and return code.
Q9: Which exception handling block is executed regardless of whether an exception occurs?
a) try
b) except
c) finally
d) else
Correct Answer: c) finally
Rationale: The finally block always executes, whether an exception occurred or not, making it ideal for
cleanup actions like closing files or releasing resources. It runs even if an exception is raised and not
caught.
Q10: How do you install an external Python package using pip?
a) pip install package_name
b) pip get package_name
c) pip add package_name
d) pip download package_name
Correct Answer: a) pip install package_name
Rationale: The standard command to install packages from the Python Package Index (PyPI) is pip install.
For specific versions, use pip install package_name==version. Use pip freeze to list installed packages.
Objective Assessment | OA V1 and V2 |
Questions and Answers | 2026/27 Update
| 100% Correct.
Section 1: Python Fundamentals & Data Types (Questions 1-12)
Q1: Which Python collection is best suited for storing an ordered sequence of elements that can be
modified?
a) Tuple
b) Set
c) List
d) Dictionary
Correct Answer: c) List
Rationale: Lists are ordered, mutable (changeable) collections. Tuples are immutable, sets are
unordered, and dictionaries store key-value pairs. Lists are ideal for tasks requiring ordered, changeable
data, such as maintaining a sequence of server names in an IT automation script.
Q2: Which data structure is ordered but immutable (cannot be modified once created)?
a) List
b) Tuple
c) Set
d) Dictionary
Correct Answer: b) Tuple
,Rationale: Tuples maintain order but cannot be modified after creation. They are used for fixed,
permanent data like coordinates or configuration constants. This immutability makes tuples hashable,
allowing them to be used as dictionary keys.
Q3: Which data structure stores unique, unordered items and automatically eliminates duplicates?
a) List
b) Tuple
c) Set
d) Dictionary
Correct Answer: c) Set
Rationale: Sets do not preserve order and automatically eliminate duplicates. They are excellent for
membership testing and filtering unique values, such as extracting unique IP addresses from log files.
Sets use hash-based lookup for O(1) membership testing.
Q4: Which data structure stores data as key-value pairs, allowing fast lookup by a descriptive key?
a) List
b) Tuple
c) Set
d) Dictionary
Correct Answer: d) Dictionary
Rationale: Dictionaries store data as key-value pairs, allowing data to be accessed using meaningful
labels rather than numeric indexes. They are ideal for representing relationships such as device names
and IP addresses. Dictionaries provide O(1) average-time complexity for lookups.
Q5: Which Python module is primarily used for interacting with the operating system (e.g., creating
directories, checking paths)?
a) sys
b) os
, c) requests
d) json
Correct Answer: b) os
Rationale: The os module provides functions for interacting with the operating system, such
as os.mkdir(), os.path.exists(), and os.getcwd(). The sys module handles system-specific
parameters, requests is for HTTP, and json is for data formatting.
Q6: What is the correct syntax to define a function in Python?
a) function my_func():
b) def my_func():
c) define my_func():
d) func my_func():
Correct Answer: b) def my_func():
Rationale: Python uses the def keyword to define functions. The syntax is def
function_name(parameters):. The colon at the end is required, and the function body must be indented.
Q7: Which method is used to read the entire content of a file into a string?
a) file.read()
b) file.readline()
c) file.readlines()
d) file.get()
Correct Answer: a) file.read()
Rationale: read() reads the entire file content as a single string. readline() reads one line at a time,
and readlines() reads all lines into a list of strings. For large files, consider reading in chunks to manage
memory.
Q8: What does the subprocess.run() function do?
, a) Runs a Python script in a new thread
b) Executes a system command and waits for it to complete
c) Runs a function asynchronously
d) Installs a Python package
Correct Answer: b) Executes a system command and waits for it to complete
Rationale: subprocess.run() is used to run system commands (like ping or dir) from within a Python
script and waits for the command to finish. It returns a CompletedProcess instance containing the
command's output and return code.
Q9: Which exception handling block is executed regardless of whether an exception occurs?
a) try
b) except
c) finally
d) else
Correct Answer: c) finally
Rationale: The finally block always executes, whether an exception occurred or not, making it ideal for
cleanup actions like closing files or releasing resources. It runs even if an exception is raised and not
caught.
Q10: How do you install an external Python package using pip?
a) pip install package_name
b) pip get package_name
c) pip add package_name
d) pip download package_name
Correct Answer: a) pip install package_name
Rationale: The standard command to install packages from the Python Package Index (PyPI) is pip install.
For specific versions, use pip install package_name==version. Use pip freeze to list installed packages.