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

Document preview thumbnail
Preview 3 out of 28 pages

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

Content preview

D 522 Exam 4 V1 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 4) | Western Governors
University
1. When using the os module, which function is best suited to verify if a file exists before

attempting to read its contents?

A. os.path.exists()


B. os.path.isfile()


C. os.access()


D. os.check_path()


Answer: A


Rationale: The os.path.exists() function returns True if a file or directory at the specified

path exists. This is a fundamental safety check in automation scripts to prevent

FileNotFoundError exceptions. Using this ensures that the script logic remains robust

when dealing with dynamic file system environments.


2. In the re module, what is the primary difference between re.search() and re.match()?

A. re.search() scans the whole string for a match anywhere, while re.match() checks only at

the beginning.


B. re.match() scans the entire string for any occurrence.

,C. re.search() looks for patterns only at the beginning of a string.


D. There is no functional difference between the two methods.


Answer: A


Rationale: The re.search() function is more flexible for log analysis because it finds

patterns regardless of their position. In contrast, re.match() will fail if the pattern is not

found at the very start of the string. Understanding this distinction is critical for IT

professionals who need to parse complex data streams.


3. Which subprocess.run() argument is used to capture the standard output and standard

error of a command?

A. capture_output=True


B. shell=True


C. check=True


D. stdout=PIPE


Answer: A


Rationale: The capture_output=True argument allows a script to store the result of an

external command in the CompletedProcess object. This is essential for processing the

results of shell commands within a Python workflow. Without this, the output is printed

directly to the terminal rather than being saved for variable manipulation.

, 4. What is the significance of the sys.argv list in Python automation scripts?

A. It stores the local environment variables of the operating system.


B. It tracks the memory usage of the running process.


C. It defines the system path for importing external libraries.


D. It is used to store the command-line arguments passed to the script.


Answer: D


Rationale: The sys.argv list is the standard way to accept user inputs or flags when

running a script from the command line. The first element, sys.argv[0], always refers to the

script name itself. This allows administrators to create versatile tools that behave

differently based on the parameters provided at runtime.


5. Which unittest method is used to verify that two values are identical during a test case?

A. assertValue()


B. assertEqual()


C. assertSame()


D. assertTrue()


Answer: B


Rationale: The assertEqual() method is the core tool for checking that the output of a

function matches the expected result. If the values do not match, the test fails and provides

Document information

Uploaded on
July 16, 2026
Number of pages
28
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$15.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