D 522 Exam 4 V3 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 4) | Western Governors
University
1. When using the subprocess module in Python, which parameter is required to capture the
output of a command so it can be processed as a string?
A. check=True
B. shell=True
C. capture_output=True
D. timeout=30
Answer: C
Rationale: The capture_output parameter is essential when you need the script to read
what the external command prints to the console. When set to True, both stdout and stderr
are captured and stored in the completed process object. This allows the automation script
to parse the result for further logic implementation.
2. In the context of Python regular expressions, what does the metacharacter ’ represent?
A. Any digit from 0 to 9
B. Any whitespace character
C. Any character except a newline
,D. Any word character including underscores
Answer: A
Rationale: The backslash d sequence is a shorthand character class that matches any
numerical digit. It is equivalent to the character range 0 through 9 in standard bracket
notation. This is frequently used in IT automation to extract IDs or port numbers from log
files.
3. Which Python method is used to remove leading and trailing whitespace from a string?
A. .strip()
B. .clean()
C. .trim()
D. .split()
Answer: A
Rationale: The strip method is a built-in string function that cleans up unwanted
whitespace at the beginning and end of a string. It is particularly useful when processing
user input or reading lines from a text file that might contain newline characters. This helps
prevent errors during string comparisons in automation scripts.
4. When working with the CSV module, which object allows you to access rows using the
column headers as keys?
A. csv.DictReader
, B. csv.reader
C. csv.writer
D. csv.ListReader
Answer: A
Rationale: The DictReader class maps the information in each row to a dictionary whose
keys are given by the optional fieldnames parameter. This makes scripts more readable
and robust because columns are accessed by name rather than index. If the CSV header
changes position, the script logic remains intact.
5. In a unit test using the unittest module, which method is automatically called before every
individual test case is executed?
A. tearDown()
B. setUp()
C. init()
D. runTest()
Answer: B
Rationale: The setUp method is designed to prepare the test fixture by initializing objects
or creating temporary files needed for testing. It ensures that every test starts with a clean
and consistent environment. This reduces code duplication across multiple test methods in
a test suite.
Automation | Actual Q&A with Rationale
(D522 Exam 4) | Western Governors
University
1. When using the subprocess module in Python, which parameter is required to capture the
output of a command so it can be processed as a string?
A. check=True
B. shell=True
C. capture_output=True
D. timeout=30
Answer: C
Rationale: The capture_output parameter is essential when you need the script to read
what the external command prints to the console. When set to True, both stdout and stderr
are captured and stored in the completed process object. This allows the automation script
to parse the result for further logic implementation.
2. In the context of Python regular expressions, what does the metacharacter ’ represent?
A. Any digit from 0 to 9
B. Any whitespace character
C. Any character except a newline
,D. Any word character including underscores
Answer: A
Rationale: The backslash d sequence is a shorthand character class that matches any
numerical digit. It is equivalent to the character range 0 through 9 in standard bracket
notation. This is frequently used in IT automation to extract IDs or port numbers from log
files.
3. Which Python method is used to remove leading and trailing whitespace from a string?
A. .strip()
B. .clean()
C. .trim()
D. .split()
Answer: A
Rationale: The strip method is a built-in string function that cleans up unwanted
whitespace at the beginning and end of a string. It is particularly useful when processing
user input or reading lines from a text file that might contain newline characters. This helps
prevent errors during string comparisons in automation scripts.
4. When working with the CSV module, which object allows you to access rows using the
column headers as keys?
A. csv.DictReader
, B. csv.reader
C. csv.writer
D. csv.ListReader
Answer: A
Rationale: The DictReader class maps the information in each row to a dictionary whose
keys are given by the optional fieldnames parameter. This makes scripts more readable
and robust because columns are accessed by name rather than index. If the CSV header
changes position, the script logic remains intact.
5. In a unit test using the unittest module, which method is automatically called before every
individual test case is executed?
A. tearDown()
B. setUp()
C. init()
D. runTest()
Answer: B
Rationale: The setUp method is designed to prepare the test fixture by initializing objects
or creating temporary files needed for testing. It ensures that every test starts with a clean
and consistent environment. This reduces code duplication across multiple test methods in
a test suite.