• 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 2 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 2) | Western Governors University

Document preview thumbnail
Preview 3 out of 29 pages

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

Content preview

D 522 Exam 2 V2 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 2) |
Western Governors University
1. When using the re module to find a pattern at the very beginning of a string, which

function is the most appropriate to use?

A. re.search()


B. re.match()


C. re.findall()


D. re.split()


Correct Answer: B


Explanation: The re.match() function is specifically designed to check for a match only

at the beginning of a string. If the pattern is found anywhere else in the string, it will return

None. This distinguishes it from re.search(), which scans the entire string for the first

location where the pattern occurs.


2. Which parameter in subprocess.run() allows the capture of standard output and

standard error for further processing in a Python script?

A. shell=True


B. check=True


C. capture_output=True

,D. timeout=60


Correct Answer: C


Explanation: The capture_output=True parameter automatically sets stdout and

stderr to subprocess.PIPE, allowing the script to access the command results via the

stdout and stderr attributes. This is essential for automation tasks that need to parse the

output of a system command to make decisions. Without this setting, the output is typically

sent directly to the console and is not accessible by the variable capturing the process

result.


3. In the unittest framework, which method is automatically called before every individual

test method to prepare the test environment?

A. tearDown()


B. setUp()


C. init()


D. runTest()


Correct Answer: B


Explanation: The setUp() method is executed by the test runner immediately before each

test case is run. This ensures that every test starts with a clean and consistent environment,

such as a fresh database connection or a specific file structure. It is a fundamental part of

the test lifecycle within the unittest module to ensure test isolation.

, 4. What is the default mode when opening a file using the open() function in Python?

A. ‘w’ (Write)


B. ‘a’ (Append)


C. ‘r’ (Read Text)


D. ‘rb’ (Read Binary)


Correct Answer: C


Explanation: The default mode for the open() function is ‘r’, which stands for reading in

text mode. If the file does not exist, this mode will raise a FileNotFoundError rather than

creating a new file. Developers should explicitly state the mode if writing or binary

operations are required to avoid logical errors in the script.


5. Which regular expression character represents any single digit from 0 to 9?

A.


B.


C.


D.


Correct Answer: C


Explanation: The \d character class is a shorthand for [0-9] in Python’s re module. It is

frequently used in automation to extract numerical data such as IDs, phone numbers, or

quantities from log files. Conversely, \D matches any character that is not a digit.

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