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

Document preview thumbnail
Preview 3 out of 28 pages

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

Content preview

D 522 Exam 1 V1 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 1) |
Western Governors University
1. In Python, which character is used to indicate the start of a shebang line in a script meant

for Unix-like environments?

A. !!


B. #!


C. //!


D. %%!


Correct Answer: B


Explanation: The shebang line starts with the characters ‘#!’ followed by the path to the

interpreter. This tells the operating system which program to use to execute the script’s

contents. It is standard practice in IT automation to include this line for portability across

different terminal environments.


2. Which module in Python is most commonly used for executing external system commands

and capturing their output?

A. sys


B. subprocess


C. os

,D. shutil


Correct Answer: B


Explanation: The subprocess module allows you to spawn new processes, connect to their

input/output/error pipes, and obtain their return codes. It is intended to replace older

modules like os.system and os.spawn. Using subprocess.run() is the current recommended

approach for simple command execution in automation scripts.


3. What does the regular expression metacharacter ’ match in a string?

A. Any alphabetical character


B. Any whitespace character


C. Any single digit


D. Any non-digit character


Correct Answer: C


Explanation: The ‘ pattern is a shorthand character class that matches any decimal digit

from 0 to 9. Regular expressions are vital in IT automation for parsing logs and validating

user input. If you wanted to match non-digits, you would use the uppercase counterpart’’.


4. When using the ‘open’ function in Python, which mode should be used to add new data to

the end of an existing file without overwriting it?

A. ‘w’


B. ‘r+’

, C. ‘x’


D. ‘a’


Correct Answer: D


Explanation: The ‘a’ mode stands for ‘append’ and ensures that all data written to the file

is added to the end. In contrast, the ‘w’ mode truncates the file to zero length before

writing, effectively deleting previous content. This distinction is critical when maintaining

continuous log files in automation workflows.


5. Which of the following data types in Python is mutable and stores key-value pairs?

A. List


B. Tuple


C. Dictionary


D. Set


Correct Answer: C


Explanation: Dictionaries are unordered collections that map unique keys to specific

values. They are mutable, meaning their contents can be modified after the dictionary is

created. This structure is highly efficient for organizing configuration data or structured

information retrieved from APIs.


6. What is the primary purpose of a ‘try…except’ block in a Python script?

A. To handle runtime errors and prevent the script from crashing

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