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

Content preview

D 522 Exam 1 V2 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 1) |
Western Governors University
1. A system administrator needs to check if a specific configuration file exists before

attempting to read it. Which function from the ‘os.path’ module is most appropriate for this

task?

A. os.path.exists()


B. os.path.isdir()


C. os.path.isfile()


D. os.path.join()


Correct Answer: A


Explanation: The os.path.exists() function is specifically designed to return True if a file or

directory at the specified path exists. This check is a fundamental step in defensive

programming to prevent FileNotFoundError exceptions during script execution. By

verifying the path before operations, the script ensures stability and allows for graceful

error handling.


2. When using the ‘subprocess’ module to run a bash command and capture its output, which

argument must be set to ‘True’ in the ‘subprocess.run()’ function to return a string instead of

bytes?

A. shell

,B. capture_output


C. check


D. text


Correct Answer: D


Explanation: The ‘text’ argument (or ‘universal_newlines’ in older versions) tells the

subprocess to handle the standard input, output, and error as strings. If this is not set, the

output is returned in byte format, which usually requires manual decoding using UTF-8.

Setting text=True simplifies data processing within the Python script significantly.


3. In Python, which built-in data type is immutable and stores an ordered sequence of

elements?

A. List


B. Dictionary


C. Tuple


D. Set


Correct Answer: C


Explanation: A tuple is defined as an immutable sequence, meaning its contents cannot be

altered once it is created. This makes tuples faster than lists and suitable for protecting

data that should not change throughout a script. They use parentheses for definition,

distinguishing them from square-bracketed lists.

, 4. A developer wants to extract all email addresses from a large log file. Which ‘re’ module

function is best suited to find all non-overlapping matches of a pattern?

A. re.search()


B. re.match()


C. re.split()


D. re.findall()


Correct Answer: D


Explanation: The re.findall() function scans the entire input string and returns a list

containing all matches of the provided regex pattern. Unlike re.search(), which only returns

the first occurrence, findall() is ideal for data scraping and log analysis. It ensures that

every instance of the pattern is captured for further processing.


5. What will be the output of the following code snippet? ‘print(“Automation”.strip(“n”))’

A. Automa


B. Automation


C. Automatio


D. tomatio


Correct Answer: C

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