• 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 29 pages
Exam (elaborations)

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

Document preview thumbnail
Preview 3 out of 29 pages

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

Content preview

D 522 Exam 3 V1 | 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 be used to find all

occurrences of a pattern and return them as a list of strings?

A. re.search()


B. re.match()


C. re.findall()


D. re.finditer()


Correct Answer: C


Explanation: The re.findall() function is specifically designed to scan the entire input

string and return all non-overlapping matches. Unlike re.search(), which only returns the

first match found, findall provides a comprehensive list of all occurrences. This is

particularly useful in IT automation when extracting multiple data points like IP addresses

or error codes from log files.


2. Which subprocess method is recommended in Python 3.5+ to execute a command and wait

for it to finish while capturing the output?

A. subprocess.call()


B. subprocess.popen()

,C. subprocess.check_call()


D. subprocess.run()


Correct Answer: D


Explanation: The subprocess.run() method was introduced as a more flexible and

powerful replacement for older functions like call() or check_call(). It allows users to

capture stdout and stderr easily by setting the capture_output parameter to True. It is the

current standard for executing external system commands within a Python script.


3. In the context of the unittest module, which method is automatically called to prepare the

test fixture before each individual test method is run?

A. initialize()


B. prepareTest()


C. tearDown()


D. setUp()


Correct Answer: D


Explanation: The setUp() method is a core component of the unittest.TestCase class that

runs before every test case to ensure a clean state. This is useful for tasks such as opening

database connections or creating temporary files needed for testing. By using setUp,

developers can reduce code duplication across multiple test methods within the same class.

, 4. Which character is used in a Regular Expression to indicate that a pattern must appear at

the very beginning of a string?

A. $


B. *


C. ^


D. ?


Correct Answer: C


Explanation: The caret (^) symbol is known as an anchor in regular expressions that

matches the start of the string or line. If the multiline flag is not used, it strictly ensures the

match begins at the absolute start of the data. This is essential for parsing structured text

where specific identifiers are expected at the beginning of each record.


5. Which module would an IT professional use to copy a directory tree from one location to

another, including all subdirectories and files?

A. shutil


B. os


C. sys


D. pathlib


Correct Answer: A

Document information

Uploaded on
September 24, 2026
Number of pages
29
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