D 522 Exam 4 V2 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 4) | Western Governors
University
1. When using the Python ‘subprocess’ module, which argument should be set to ‘True’ in the
run() function to capture the standard output and standard error for further processing?
A. capture_output
B. shell
C. check
D. timeout
Answer: A
Rationale: The ‘capture_output’ argument is used to capture the output of the command
execution in the subprocess.run() function. When set to True, it ensures that both stdout
and stderr are captured and stored in the returned CompletedProcess object. This is
essential for automation scripts that need to parse the results of external system
commands.
2. Which regular expression character is used to match the beginning of a string?
A. ^
B. *
,C. $
D. +
Answer: A
Rationale: The caret symbol (^) is a meta-character used in regular expressions to signify
the start of a string or line. It ensures that the pattern search begins exactly at the first
character position. Understanding these anchors is fundamental for valid string parsing
and data extraction tasks.
3. In the ‘requests’ library, which HTTP method is typically used to update an existing
resource with new data?
A. PUT
B. GET
C. DELETE
D. HEAD
Answer: A
Rationale: The PUT method in HTTP protocol is specifically designed to replace an existing
resource or create it if it does not exist at a specific URI. In Python’s requests library,
‘requests.put()’ is used to send this type of request to a REST API. This method is
idempotent, meaning multiple identical requests should have the same effect as a single
one.
, 4. Which method from the ‘os’ module should an IT professional use to delete a file that is no
longer needed by an automation script?
A. os.rmdir()
B. os.delete()
C. os.clear()
D. os.remove()
Answer: D
Rationale: The ‘os.remove()’ function is used to delete a file path from the system. It is
important to note that ‘os.rmdir()’ is used specifically for empty directories, not files. Using
the correct removal function prevents execution errors when managing local file system
storage.
5. What is the purpose of the ‘json.loads()’ function in Python?
A. To convert a Python dictionary into a JSON string.
B. To read a JSON file and load it into a Python object.
C. To parse a JSON-formatted string and convert it into a Python dictionary.
D. To validate the syntax of a JSON schema.
Answer: C
Rationale: The ‘json.loads()’ function stands for ‘load string’ and is used to deserialize a
string containing JSON data into a Python object, such as a dictionary or list. This is distinct
Automation | Actual Q&A with Rationale
(D522 Exam 4) | Western Governors
University
1. When using the Python ‘subprocess’ module, which argument should be set to ‘True’ in the
run() function to capture the standard output and standard error for further processing?
A. capture_output
B. shell
C. check
D. timeout
Answer: A
Rationale: The ‘capture_output’ argument is used to capture the output of the command
execution in the subprocess.run() function. When set to True, it ensures that both stdout
and stderr are captured and stored in the returned CompletedProcess object. This is
essential for automation scripts that need to parse the results of external system
commands.
2. Which regular expression character is used to match the beginning of a string?
A. ^
B. *
,C. $
D. +
Answer: A
Rationale: The caret symbol (^) is a meta-character used in regular expressions to signify
the start of a string or line. It ensures that the pattern search begins exactly at the first
character position. Understanding these anchors is fundamental for valid string parsing
and data extraction tasks.
3. In the ‘requests’ library, which HTTP method is typically used to update an existing
resource with new data?
A. PUT
B. GET
C. DELETE
D. HEAD
Answer: A
Rationale: The PUT method in HTTP protocol is specifically designed to replace an existing
resource or create it if it does not exist at a specific URI. In Python’s requests library,
‘requests.put()’ is used to send this type of request to a REST API. This method is
idempotent, meaning multiple identical requests should have the same effect as a single
one.
, 4. Which method from the ‘os’ module should an IT professional use to delete a file that is no
longer needed by an automation script?
A. os.rmdir()
B. os.delete()
C. os.clear()
D. os.remove()
Answer: D
Rationale: The ‘os.remove()’ function is used to delete a file path from the system. It is
important to note that ‘os.rmdir()’ is used specifically for empty directories, not files. Using
the correct removal function prevents execution errors when managing local file system
storage.
5. What is the purpose of the ‘json.loads()’ function in Python?
A. To convert a Python dictionary into a JSON string.
B. To read a JSON file and load it into a Python object.
C. To parse a JSON-formatted string and convert it into a Python dictionary.
D. To validate the syntax of a JSON schema.
Answer: C
Rationale: The ‘json.loads()’ function stands for ‘load string’ and is used to deserialize a
string containing JSON data into a Python object, such as a dictionary or list. This is distinct