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 throughout the script?
A. list
B. set
C. tuple
D. dict
Correct Answer: C
Rationale: A tuple (C) is immutable and can hold unique strings; using it prevents accidental
mutation and conveys intent that the collection should not change. A list (A) is mutable and
allows duplicates. A set (B) is mutable and unordered, making it unsuitable when order must be
preserved. A dict (D) is mutable and keyed, which is unnecessary for 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: In Python a lambda expression creates an anonymous function object whose runtime
type is function (A). There is no separate lambda type (B). It is neither a bound method (C) nor
an integer (D).
3. Which statement accurately describes the difference between a Python module and a
package?
A. A module is a single .py file; a package is a directory containing an init.py file and possibly
sub-modules.
B. A module can contain multiple packages; a package cannot contain modules.
C. There is no difference; the terms are interchangeable.
D. A package must be compiled before use, whereas a module is interpreted.
Correct Answer: A
,Rationale: A module is indeed a single file (A), while a package is a directory with an init.py
marker that can contain sub-modules or sub-packages. Option B reverses the relationship. Option
C is false. Option D confuses packages with compiled extensions.
4. Which exception will be raised if subprocess.run(['ping', '-c', '1',
'192.168.1.1'], check=True) receives no reply from the target?
A. ConnectionError
B. subprocess.CalledProcessError
C. TimeoutError
D. OSError
Correct Answer: B
Rationale: When check=True the shell return-code becomes an exception; ping returns
non-zero on no reply, raising CalledProcessError (B). ConnectionError (A) is for
sockets. TimeoutError (C) requires a timeout parameter. OSError (D) is too generic and
not triggered here.
5. Which re pattern correctly matches an IPv4 dotted-quad address in a log line?
A. r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}'
B. r'[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}'
, C. r'\d+.\d+.\d+.\d+'
D. r'(\d{1,3}.){3}\d{1,3}'
Correct Answer: D
Rationale: Pattern D groups three repetitions of digits followed by a dot and then a final digit
group, efficiently matching dotted quads. A and B are verbose but correct; D is more compact. C
is too greedy and could match invalid lengths.
6. Which pathlib method returns a new Path object with the file suffix changed?
A. with_suffix()
B. suffix()
C. rename()
D. replace_suffix()
Correct Answer: A
Rationale: Path.with_suffix('.new') (A) returns a new Path object with the extension
altered without renaming the file itself. suffix (B) is a read-only property. rename() (C)
moves/renames the actual file. There is no replace_suffix() (D).
7. What is the purpose of if __name__ == '__main__': in a Python automation
script?
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 throughout the script?
A. list
B. set
C. tuple
D. dict
Correct Answer: C
Rationale: A tuple (C) is immutable and can hold unique strings; using it prevents accidental
mutation and conveys intent that the collection should not change. A list (A) is mutable and
allows duplicates. A set (B) is mutable and unordered, making it unsuitable when order must be
preserved. A dict (D) is mutable and keyed, which is unnecessary for 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: In Python a lambda expression creates an anonymous function object whose runtime
type is function (A). There is no separate lambda type (B). It is neither a bound method (C) nor
an integer (D).
3. Which statement accurately describes the difference between a Python module and a
package?
A. A module is a single .py file; a package is a directory containing an init.py file and possibly
sub-modules.
B. A module can contain multiple packages; a package cannot contain modules.
C. There is no difference; the terms are interchangeable.
D. A package must be compiled before use, whereas a module is interpreted.
Correct Answer: A
,Rationale: A module is indeed a single file (A), while a package is a directory with an init.py
marker that can contain sub-modules or sub-packages. Option B reverses the relationship. Option
C is false. Option D confuses packages with compiled extensions.
4. Which exception will be raised if subprocess.run(['ping', '-c', '1',
'192.168.1.1'], check=True) receives no reply from the target?
A. ConnectionError
B. subprocess.CalledProcessError
C. TimeoutError
D. OSError
Correct Answer: B
Rationale: When check=True the shell return-code becomes an exception; ping returns
non-zero on no reply, raising CalledProcessError (B). ConnectionError (A) is for
sockets. TimeoutError (C) requires a timeout parameter. OSError (D) is too generic and
not triggered here.
5. Which re pattern correctly matches an IPv4 dotted-quad address in a log line?
A. r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}'
B. r'[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}'
, C. r'\d+.\d+.\d+.\d+'
D. r'(\d{1,3}.){3}\d{1,3}'
Correct Answer: D
Rationale: Pattern D groups three repetitions of digits followed by a dot and then a final digit
group, efficiently matching dotted quads. A and B are verbose but correct; D is more compact. C
is too greedy and could match invalid lengths.
6. Which pathlib method returns a new Path object with the file suffix changed?
A. with_suffix()
B. suffix()
C. rename()
D. replace_suffix()
Correct Answer: A
Rationale: Path.with_suffix('.new') (A) returns a new Path object with the extension
altered without renaming the file itself. suffix (B) is a read-only property. rename() (C)
moves/renames the actual file. There is no replace_suffix() (D).
7. What is the purpose of if __name__ == '__main__': in a Python automation
script?