Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 28 pages
Exam (elaborations)

D 522 Exam 3 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 3) | Western Governors University

Document preview thumbnail
Preview 3 out of 28 pages

D 522 Exam 3 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 3) | Western Governors University

Content preview

D 522 Exam 3 V2 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 3) | Western Governors
University
1. When using the ‘re’ module in Python, which function should an IT professional use to find

all occurrences of a pattern within a string?

A. re.search()


B. re.findall()


C. re.match()


D. re.split()


Answer: B


Rationale: The re.findall() function is designed to scan the entire string and return all non-

overlapping matches of a pattern as a list of strings. In contrast, re.search() only identifies

the first occurrence of the pattern. Using findall ensures that every instance of the data,

such as IP addresses in a log file, is captured for processing.


2. An automation script needs to check if a specific command-line argument was provided.

Which index of ‘sys.argv’ contains the name of the script itself?

A. sys.argv.name


B. sys.argv[1]

,C. sys.argv[-1]


D. sys.argv[0]


Answer: D


Rationale: The sys.argv list is the standard way to access command-line arguments in

Python scripts. The element at index 0 is always the name of the script being executed by

the interpreter. To access actual user-provided arguments, the script must look at index 1

and beyond.


3. Which subprocess method is recommended for executing a command and waiting for it to

complete in Python 3.5+?

A. subprocess.call()


B. subprocess.exec()


C. subprocess.popen()


D. subprocess.run()


Answer: D


Rationale: The subprocess.run() function was introduced to simplify the process of

starting a process and waiting for it to finish. It returns a CompletedProcess instance which

includes information about the exit status and output. While subprocess.call exists for

backward compatibility, run() is the current standard for basic automation tasks.

, 4. What is the purpose of the ‘capture_output=True’ argument in the subprocess.run()

function?

A. It displays the output directly to the user’s terminal.


B. It saves the output to a text file on the local disk.


C. It prevents the command from generating any output at all.


D. It allows the script to store stdout and stderr in the returned object.


Answer: D


Rationale: By setting capture_output to True, the script instructs the subprocess to

redirect standard output and standard error to pipes. These streams can then be accessed

via the stdout and stderr attributes of the returned CompletedProcess object. This is

essential for scripts that need to parse the results of a system command to make decisions.


5. Which regular expression metacharacter is used to match the start of a string?

A. $


B. *


C. ^


D. +


Answer: C


Rationale: The caret symbol (^) is an anchor in regular expressions that specifies the

match must occur at the beginning of the string. This is useful for identifying log entries

Document information

Uploaded on
July 16, 2026
Number of pages
28
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$16.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ScholarsAscend
3.7
(77)
Sold
453
Followers
39
Items
29361
Last sold
11 hours ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions