WGU D522 Objective Assessment | Python for IT
Automation | ACTUAL EXAM | Questions &
Verified Answers | Latest Update –
Western Governors University
1
Which Python data type is best suited for storing a fixed collection of unique IP-address
strings that must remain immutable?
A. list
B. set
C. tuple
D. dict
Correct Answer: C
Rationale: A tuple is immutable and can contain unique strings; once created its
members cannot be reassigned, guaranteeing fixed content. A list (A) is mutable and
allows duplicates. A set (B) is mutable and unordered, so it cannot be “fixed” at runtime.
A dict (D) is mutable and requires key–value pairs, which is unnecessary overhead for a
simple collection of IPs.
,2
What is the output of the following snippet?
print(type(lambda x: x * 2))
A. <class 'function'>
B. <class 'lambda'>
C. <class 'method'>
D. <class 'builtin_function_or_method'>
Correct Answer: A
Rationale: A lambda expression creates an anonymous function object; therefore type()
returns <class 'function'>. There is no separate lambda type (B). It is neither a bound
method (C) nor a built-in (D).
3
Which statement about Python’s Global Interpreter Lock (GIL) is TRUE in CPython
3.11?
A. It allows true parallel execution of Python byte-code in multiple threads of the same
process.
,B. It is released automatically during I/O-bound operations written in Python.
C. It is bypassed when using the multiprocessing module because each process has its
own interpreter.
D. It can be disabled globally at runtime using sys.setgil(False).
Correct Answer: C
Rationale: The multiprocessing module spawns separate processes, each with its own
Python interpreter and memory space, thus avoiding the GIL. The GIL does NOT allow
parallel byte-code execution in threads (A). It is released in C extensions, not pure
Python I/O (B). No official sys.setgil(False) exists (D).
4
Which module from the Python standard library is the MOST appropriate choice for
creating a sandboxed, high-performance virtual environment without internet access?
A. zipapp
B. pyvenv
C. venv
D. ensurepip
Correct Answer: C
, Rationale: venv is the standard, lightweight module for creating virtual environments; it
supports --without-pip to remain offline. zipapp (A) packages apps but does not
sandbox. pyvenv (B) is deprecated. ensurepip (D) only bootstraps pip.
5
Given import re and the string s = "", which pattern
extracts ONLY the numeric portion of the username?
A. re.search(r'\d+', s).group()
B. re.findall(r'user(\d+)', s)[0]
C. re.match(r'.?(\d+).', s).group(1)
D. re.split(r'\D+', s)[1]
Correct Answer: A
Rationale: Pattern \d+ matches one or more digits anywhere; search finds the first
occurrence and .group() returns "123". Option B assumes literal "user" prefix. Option C
works but is verbose. Option D splits on non-digits and indexing may fail if digits appear
elsewhere.
6
Which subprocess call correctly redirects both stdout and stderr of ping -c 1
8.8.8.8 to a single file-like object while suppressing terminal output?
Automation | ACTUAL EXAM | Questions &
Verified Answers | Latest Update –
Western Governors University
1
Which Python data type is best suited for storing a fixed collection of unique IP-address
strings that must remain immutable?
A. list
B. set
C. tuple
D. dict
Correct Answer: C
Rationale: A tuple is immutable and can contain unique strings; once created its
members cannot be reassigned, guaranteeing fixed content. A list (A) is mutable and
allows duplicates. A set (B) is mutable and unordered, so it cannot be “fixed” at runtime.
A dict (D) is mutable and requires key–value pairs, which is unnecessary overhead for a
simple collection of IPs.
,2
What is the output of the following snippet?
print(type(lambda x: x * 2))
A. <class 'function'>
B. <class 'lambda'>
C. <class 'method'>
D. <class 'builtin_function_or_method'>
Correct Answer: A
Rationale: A lambda expression creates an anonymous function object; therefore type()
returns <class 'function'>. There is no separate lambda type (B). It is neither a bound
method (C) nor a built-in (D).
3
Which statement about Python’s Global Interpreter Lock (GIL) is TRUE in CPython
3.11?
A. It allows true parallel execution of Python byte-code in multiple threads of the same
process.
,B. It is released automatically during I/O-bound operations written in Python.
C. It is bypassed when using the multiprocessing module because each process has its
own interpreter.
D. It can be disabled globally at runtime using sys.setgil(False).
Correct Answer: C
Rationale: The multiprocessing module spawns separate processes, each with its own
Python interpreter and memory space, thus avoiding the GIL. The GIL does NOT allow
parallel byte-code execution in threads (A). It is released in C extensions, not pure
Python I/O (B). No official sys.setgil(False) exists (D).
4
Which module from the Python standard library is the MOST appropriate choice for
creating a sandboxed, high-performance virtual environment without internet access?
A. zipapp
B. pyvenv
C. venv
D. ensurepip
Correct Answer: C
, Rationale: venv is the standard, lightweight module for creating virtual environments; it
supports --without-pip to remain offline. zipapp (A) packages apps but does not
sandbox. pyvenv (B) is deprecated. ensurepip (D) only bootstraps pip.
5
Given import re and the string s = "", which pattern
extracts ONLY the numeric portion of the username?
A. re.search(r'\d+', s).group()
B. re.findall(r'user(\d+)', s)[0]
C. re.match(r'.?(\d+).', s).group(1)
D. re.split(r'\D+', s)[1]
Correct Answer: A
Rationale: Pattern \d+ matches one or more digits anywhere; search finds the first
occurrence and .group() returns "123". Option B assumes literal "user" prefix. Option C
works but is verbose. Option D splits on non-digits and indexing may fail if digits appear
elsewhere.
6
Which subprocess call correctly redirects both stdout and stderr of ping -c 1
8.8.8.8 to a single file-like object while suppressing terminal output?