• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 28 pages
Exam (elaborations)

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

Document preview thumbnail
Preview 3 out of 28 pages

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

Content preview

D 522 Exam 2 V1 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 2) |
Western Governors University
1. When using the subprocess module, which parameter in subprocess.run() is used to

capture output that would normally be sent to the console?

A. output_stream


B. capture_output


C. save_stdout


D. log_results


Correct Answer: B


Explanation: The capture_output parameter is set to True to capture both stdout and

stderr. By default, subprocess.run() displays output to the screen without storing it. Setting

this to True allows the developer to access the data via the stdout and stderr attributes of

the returned object.


2. Which regular expression symbol is used to match the start of a string in Python’s re

module?

A. $


B. ^


C. *

,D. &


Correct Answer: B


Explanation: The caret symbol (^) serves as an anchor in regular expressions to signify the

beginning of a line or string. It ensures that the pattern match only occurs if it is found at

the very start. This is commonly used in log analysis to find entries that begin with specific

timestamps or levels.


3. In the context of Python unit testing, what is the primary purpose of the setUp() method?

A. To configure the test environment before each individual test method


B. To define the sequence in which tests are executed


C. To clean up resources after all tests run


D. To generate the final test report


Correct Answer: A


Explanation: The setUp() method is part of the unittest.TestCase class and runs

automatically before every test method. It is used to initialize variables, open files, or

establish database connections needed for testing. This ensures that every test starts with a

fresh, consistent environment.


4. Which value does a successful subprocess return code typically equate to in a Linux-based

environment?

A. 1

, B. 0


C. -1


D. None


Correct Answer: B


Explanation: A return code of 0 indicates that the process finished successfully without

errors. Any non-zero return code is generally interpreted as a failure or a specific error

state. IT automation scripts frequently check this return code to decide if subsequent tasks

should proceed.


5. What is the result of using the re.search() function if no match is found in the target string?

A. It returns None


B. It returns an empty string


C. It returns a False boolean


D. It raises a MatchNotFoundError


Correct Answer: A


Explanation: When re.search() fails to find a pattern, it returns the Python None object

rather than raising an exception. Developers must check if the result is not None before

attempting to access groups or match data. This behavior allows for simple conditional

logic in search loops.

Document information

Uploaded on
September 24, 2026
Number of pages
28
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$19.38

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.
Shinnie
3.6
(7)
Sold
27
Followers
0
Items
4868
Last sold
1 week 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