D 522 Exam 4 V1 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 4) |
Western Governors University
1. When using the Python ‘re’ module, which character is used to match the start of a string?
A. ^
B. $
C. *
D. ?
Correct Answer: A
Explanation: The caret symbol (^) is used in regular expressions to anchor the match to
the beginning of a string. This is crucial for identifying lines in logs that start with specific
patterns. Using the ‘$’ symbol would instead anchor the match to the end of the string.
2. In the ‘subprocess’ module, what is the purpose of the ‘capture_output=True’ argument?
A. It terminates the process if it takes too long.
B. It allows the script to read the standard output and standard error of the command.
C. It causes the process to run in the background.
D. It automatically deletes the output files created by the command.
Correct Answer: B
,Explanation: Setting capture_output to True allows the Python script to store the result of
the command in the completed process object. This allows for further processing of the
command’s results within the script logic. Without this, the output is directed to the system
console by default.
3. Which method from the ‘unittest’ module is used to verify that two values are the same?
A. assertTrue()
B. assertEqual()
C. assertMatch()
D. assertVerify()
Correct Answer: B
Explanation: The assertEqual method is the standard way to check for equality between
an expected result and the actual result in a test case. It is part of the unittest.TestCase class
provided by the standard library. If the values do not match, the test will fail and report the
discrepancy.
4. What is the default log level for the Python ‘logging’ module?
A. DEBUG
B. WARNING
C. INFO
D. ERROR
, Correct Answer: B
Explanation: By default, the logging module is configured to only display messages with a
level of WARNING or higher. This means that DEBUG and INFO messages will be
suppressed unless the configuration is explicitly changed. Understanding log levels helps
developers manage the verbosity of automation scripts.
5. Which function is used to convert a Python dictionary into a JSON-formatted string?
A. json.load()
B. json.dumps()
C. json.loads()
D. json.dump()
Correct Answer: B
Explanation: The json.dumps() function takes a Python object and returns its JSON string
representation. Note that the ‘s’ in ‘dumps’ stands for ‘string’. This is commonly used when
sending data to web APIs or storing configuration as text.
6. What does the ‘os.path.exists()’ function return if a file is found?
A. The file path as a string
B. A boolean True
C. The file size
D. A file object
| Actual Q&A with Rationale (D522 Exam 4) |
Western Governors University
1. When using the Python ‘re’ module, which character is used to match the start of a string?
A. ^
B. $
C. *
D. ?
Correct Answer: A
Explanation: The caret symbol (^) is used in regular expressions to anchor the match to
the beginning of a string. This is crucial for identifying lines in logs that start with specific
patterns. Using the ‘$’ symbol would instead anchor the match to the end of the string.
2. In the ‘subprocess’ module, what is the purpose of the ‘capture_output=True’ argument?
A. It terminates the process if it takes too long.
B. It allows the script to read the standard output and standard error of the command.
C. It causes the process to run in the background.
D. It automatically deletes the output files created by the command.
Correct Answer: B
,Explanation: Setting capture_output to True allows the Python script to store the result of
the command in the completed process object. This allows for further processing of the
command’s results within the script logic. Without this, the output is directed to the system
console by default.
3. Which method from the ‘unittest’ module is used to verify that two values are the same?
A. assertTrue()
B. assertEqual()
C. assertMatch()
D. assertVerify()
Correct Answer: B
Explanation: The assertEqual method is the standard way to check for equality between
an expected result and the actual result in a test case. It is part of the unittest.TestCase class
provided by the standard library. If the values do not match, the test will fail and report the
discrepancy.
4. What is the default log level for the Python ‘logging’ module?
A. DEBUG
B. WARNING
C. INFO
D. ERROR
, Correct Answer: B
Explanation: By default, the logging module is configured to only display messages with a
level of WARNING or higher. This means that DEBUG and INFO messages will be
suppressed unless the configuration is explicitly changed. Understanding log levels helps
developers manage the verbosity of automation scripts.
5. Which function is used to convert a Python dictionary into a JSON-formatted string?
A. json.load()
B. json.dumps()
C. json.loads()
D. json.dump()
Correct Answer: B
Explanation: The json.dumps() function takes a Python object and returns its JSON string
representation. Note that the ‘s’ in ‘dumps’ stands for ‘string’. This is commonly used when
sending data to web APIs or storing configuration as text.
6. What does the ‘os.path.exists()’ function return if a file is found?
A. The file path as a string
B. A boolean True
C. The file size
D. A file object