WGU D522 Objective Assessment | Python for IT Automation |
ACTUAL EXAM | Questions & Verified Answers | Latest 2025 /
2026 Update – Western Governors University
1.
Which Python data type is best suited to store a static lookup table that maps VLAN IDs
(integers) to VLAN names (strings) and provides O(1) average-time lookups?
A. list
B. set
C. dict
D. tuple
Correct Answer: C
Rationale: A dict (hash map) gives constant-time average lookups via hashing. A list (A)
would require O(n) linear search. A set (B) only stores keys, not key-value pairs. A tuple
(D) is immutable and lacks efficient keyed access.
2.
What is the output of the following snippet?
PythonCopy
x = [1, 2, 3]
y = x
x.append(4)
print(y)
A. [1, 2, 3]
,B. [1, 2, 3, 4]
C. [4, 3, 2, 1]
D. TypeError
Correct Answer: B
Rationale: Both x and y reference the same list object in memory; mutating via either
name is visible through both. Appending 4 modifies the shared object, so y reflects the
change. No error occurs because list.append is valid.
3.
Which statement about Python’s Global Interpreter Lock (GIL) is accurate in CPython
3.11?
A. It allows true parallel execution of multiple threads in a single process.
B. It is released during I/O-bound operations, enabling concurrency.
C. It is bypassed automatically when using the multiprocessing module.
D. Both B and C are correct.
Correct Answer: D
Rationale: The GIL prevents simultaneous execution of Python bytecode by multiple
threads in one process (so A is false), but it is released around blocking I/O syscalls (B),
and the multiprocessing module creates separate processes, each with its own GIL (C),
enabling true parallelism.
4.
Which exception will be raised by int('abc')?
,A. ValueError
B. TypeError
C. SyntaxError
D. OverflowError
Correct Answer: A
Rationale: int() cannot parse the non-numeric string, raising ValueError. TypeError (B)
occurs when the argument type is wrong (e.g., int(None)). SyntaxError (C) is for invalid
Python code, and OverflowError (D) is for numbers too large.
5.
Given re.search(r'^\d{3}-\d{3}-\d{4}$', phone), which string will match?
A. "555-123-4567"
B. "5551234567"
C. "(555) 123-4567"
D. "555-123-456"
Correct Answer: A
Rationale: The regex anchors at start/end and requires exactly three digits, hyphen,
three digits, hyphen, four digits. Only A fits. B lacks hyphens, C uses parentheses and
space, D has only three final digits.
6.
, Which subprocess call safely executes ls -l /tmp and captures stdout as a string
while suppressing stderr?
A. subprocess.run(['ls', '-l', '/tmp'], stderr=subprocess.PIPE).stdout
B. subprocess.call('ls -l /tmp', shell=True, stderr=subprocess.DEVNULL)
C. subprocess.check_output(['ls', '-l', '/tmp'], stderr=subprocess.DEVNULL).decode()
D. os.system('ls -l /tmp 2>/dev/null')
Correct Answer: C
Rationale: check_output returns stdout bytes; decoding gives the string, and DEVNULL
discards stderr. Option A is missing decode and may return None if stdout not piped. B
returns exit code only. D does not capture output in Python and uses os.system, which
is discouraged.
7.
What is returned by sorted({'b': 2, 'a': 1})?
A. {'a': 1, 'b': 2}
B. ['a', 'b']
C. ['b', 'a']
D. TypeError
Correct Answer: B
Rationale: sorted() iterates over dictionary keys (insertion-ordered in 3.7+) and returns a
new list of those keys in ascending order. It does not return the dict (A) or values (C).
ACTUAL EXAM | Questions & Verified Answers | Latest 2025 /
2026 Update – Western Governors University
1.
Which Python data type is best suited to store a static lookup table that maps VLAN IDs
(integers) to VLAN names (strings) and provides O(1) average-time lookups?
A. list
B. set
C. dict
D. tuple
Correct Answer: C
Rationale: A dict (hash map) gives constant-time average lookups via hashing. A list (A)
would require O(n) linear search. A set (B) only stores keys, not key-value pairs. A tuple
(D) is immutable and lacks efficient keyed access.
2.
What is the output of the following snippet?
PythonCopy
x = [1, 2, 3]
y = x
x.append(4)
print(y)
A. [1, 2, 3]
,B. [1, 2, 3, 4]
C. [4, 3, 2, 1]
D. TypeError
Correct Answer: B
Rationale: Both x and y reference the same list object in memory; mutating via either
name is visible through both. Appending 4 modifies the shared object, so y reflects the
change. No error occurs because list.append is valid.
3.
Which statement about Python’s Global Interpreter Lock (GIL) is accurate in CPython
3.11?
A. It allows true parallel execution of multiple threads in a single process.
B. It is released during I/O-bound operations, enabling concurrency.
C. It is bypassed automatically when using the multiprocessing module.
D. Both B and C are correct.
Correct Answer: D
Rationale: The GIL prevents simultaneous execution of Python bytecode by multiple
threads in one process (so A is false), but it is released around blocking I/O syscalls (B),
and the multiprocessing module creates separate processes, each with its own GIL (C),
enabling true parallelism.
4.
Which exception will be raised by int('abc')?
,A. ValueError
B. TypeError
C. SyntaxError
D. OverflowError
Correct Answer: A
Rationale: int() cannot parse the non-numeric string, raising ValueError. TypeError (B)
occurs when the argument type is wrong (e.g., int(None)). SyntaxError (C) is for invalid
Python code, and OverflowError (D) is for numbers too large.
5.
Given re.search(r'^\d{3}-\d{3}-\d{4}$', phone), which string will match?
A. "555-123-4567"
B. "5551234567"
C. "(555) 123-4567"
D. "555-123-456"
Correct Answer: A
Rationale: The regex anchors at start/end and requires exactly three digits, hyphen,
three digits, hyphen, four digits. Only A fits. B lacks hyphens, C uses parentheses and
space, D has only three final digits.
6.
, Which subprocess call safely executes ls -l /tmp and captures stdout as a string
while suppressing stderr?
A. subprocess.run(['ls', '-l', '/tmp'], stderr=subprocess.PIPE).stdout
B. subprocess.call('ls -l /tmp', shell=True, stderr=subprocess.DEVNULL)
C. subprocess.check_output(['ls', '-l', '/tmp'], stderr=subprocess.DEVNULL).decode()
D. os.system('ls -l /tmp 2>/dev/null')
Correct Answer: C
Rationale: check_output returns stdout bytes; decoding gives the string, and DEVNULL
discards stderr. Option A is missing decode and may return None if stdout not piped. B
returns exit code only. D does not capture output in Python and uses os.system, which
is discouraged.
7.
What is returned by sorted({'b': 2, 'a': 1})?
A. {'a': 1, 'b': 2}
B. ['a', 'b']
C. ['b', 'a']
D. TypeError
Correct Answer: B
Rationale: sorted() iterates over dictionary keys (insertion-ordered in 3.7+) and returns a
new list of those keys in ascending order. It does not return the dict (A) or values (C).