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

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

Document preview thumbnail
Preview 3 out of 27 pages

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

Content preview

D 522 Exam 1 V3 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 1) |
Western Governors University
1. When using the subprocess.run() function, which parameter is required to capture the

output of a command so it can be used later in the script?

A. capture_output=True


B. check=True


C. shell=True


D. timeout=30


Correct Answer: A


Explanation: The capture_output parameter is used to indicate that the standard output

and standard error should be captured. By setting this to True, the script can access the

command result via the stdout attribute. This is essential for automation tasks that need to

parse results from shell commands.


2. Which method should be used to retrieve a value from a dictionary while providing a

default value if the key does not exist?

A. dict.get()


B. dict.items()


C. dict.pop()

,D. dict.keys()


Correct Answer: A


Explanation: The get() method allows you to look up a key and specify a default return

value if the key is missing. This prevents the script from raising a KeyError and stopping

execution. It is a best practice in Python for safely accessing dictionary data.


3. In a Python script, what does sys.argv[0] represent?

A. The first command-line argument provided by the user


B. The name of the script being executed


C. The number of arguments passed to the script


D. The Python interpreter version


Correct Answer: B


Explanation: In the sys.argv list, the first element at index 0 is always the name of the

script itself. Subsequent elements contain the actual arguments provided by the user.

Understanding this indexing is vital for correctly parsing command-line inputs in IT

automation.


4. Which regular expression character is used to match the start of a string?

A. ^


B. *


C. $

, D. +


Correct Answer: A


Explanation: The caret symbol (^) is a boundary anchor that matches the beginning of a

line or string. It ensures that the pattern search starts specifically at the first character. This

is commonly used in log parsing to identify lines starting with specific timestamps or error

levels.


5. What is the purpose of the ‘with’ statement when opening a file in Python?

A. To ensure the file is automatically closed after the block is finished


B. To speed up the file reading process


C. To encrypt the file contents while reading


D. To allow multiple scripts to write to the file at once


Correct Answer: A


Explanation: The with statement acts as a context manager that handles resource

allocation and deallocation. It guarantees that the file will be closed even if an exception

occurs during the execution of the block. This practice prevents memory leaks and file

corruption in long-running automation tasks.


6. Which of the following functions from the ‘os’ module is used to list all files and directories

in a given path?

A. os.path.exists()

Document information

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