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
host-names that must remain immutable?
A. list
B. set
C. tuple
D. dict
Correct Answer: C
Rationale: A tuple is immutable and, when it contains only strings, can be used as a
constant collection; sets (B) are mutable, lists (A) are ordered but mutable, and dict (D)
is mapping, not a simple collection.
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 'int'>
Correct Answer: A
Rationale: A lambda expression creates an anonymous function object whose type is
function; Python has no separate lambda class (B), and it is neither a bound method (C)
nor an int (D).
3
Which statement accurately describes the difference between shutil.copy() and
shutil.copy2() in Python 3.12?
A. copy() duplicates file data and metadata; copy2() duplicates only data.
B. copy2() preserves original timestamps and mode bits; copy() does not.
C. copy() works on directories; copy2() works only on files.
D. copy2() returns a file handle; copy() returns None.
Correct Answer: B
Rationale: copy2() attempts to preserve all metadata including atime/mtime, whereas
copy() duplicates content and permission bits but not timestamps; neither returns a
handle (D) and both operate on files, not directories (C).
4
,A script uses subprocess.run(["ping", "-c", "2", "8.8.8.8"], capture_output=True, text=True)
and later prints proc.stderr. Which argument addition will discard all output and prevent
shell injection when the address is variable?
A. shell=True
B. stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
C. stdin=subprocess.PIPE
D. check=True
Correct Answer: B
Rationale: Redirecting both streams to DEVNULL silences output and avoids injection
because no shell is invoked; shell=True (A) increases injection risk, while PIPE (C) and
check (D) do not discard data.
5
Which regular-expression pattern matches only a valid dotted-decimal IPv4 address in
capture group 1?
A. ^(\d{1,3}.){3}\d{1,3}
B.
(
[0−9]1,3
, )
˙
3[0−9]1,3
C. ^((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d).){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)
D.
(
\d+
)
˙
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
host-names that must remain immutable?
A. list
B. set
C. tuple
D. dict
Correct Answer: C
Rationale: A tuple is immutable and, when it contains only strings, can be used as a
constant collection; sets (B) are mutable, lists (A) are ordered but mutable, and dict (D)
is mapping, not a simple collection.
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 'int'>
Correct Answer: A
Rationale: A lambda expression creates an anonymous function object whose type is
function; Python has no separate lambda class (B), and it is neither a bound method (C)
nor an int (D).
3
Which statement accurately describes the difference between shutil.copy() and
shutil.copy2() in Python 3.12?
A. copy() duplicates file data and metadata; copy2() duplicates only data.
B. copy2() preserves original timestamps and mode bits; copy() does not.
C. copy() works on directories; copy2() works only on files.
D. copy2() returns a file handle; copy() returns None.
Correct Answer: B
Rationale: copy2() attempts to preserve all metadata including atime/mtime, whereas
copy() duplicates content and permission bits but not timestamps; neither returns a
handle (D) and both operate on files, not directories (C).
4
,A script uses subprocess.run(["ping", "-c", "2", "8.8.8.8"], capture_output=True, text=True)
and later prints proc.stderr. Which argument addition will discard all output and prevent
shell injection when the address is variable?
A. shell=True
B. stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
C. stdin=subprocess.PIPE
D. check=True
Correct Answer: B
Rationale: Redirecting both streams to DEVNULL silences output and avoids injection
because no shell is invoked; shell=True (A) increases injection risk, while PIPE (C) and
check (D) do not discard data.
5
Which regular-expression pattern matches only a valid dotted-decimal IPv4 address in
capture group 1?
A. ^(\d{1,3}.){3}\d{1,3}
B.
(
[0−9]1,3
, )
˙
3[0−9]1,3
C. ^((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d).){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)
D.
(
\d+
)
˙