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

Document preview thumbnail
Preview 3 out of 28 pages

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

Content preview

D 522 Exam 3 V3 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 3) |
Western Governors University
1. When using the ‘re’ module in Python, which function should a developer use to find all

non-overlapping occurrences of a pattern in a string and return them as a list?

A. re.findall()


B. re.match()


C. re.search()


D. re.finditer()


Correct Answer: A


Explanation: The re.findall() function scans the target string from left to right and extracts

every instance that matches the pattern. It returns a list of strings if there are no groups in

the pattern, whereas re.search only returns the first match object. This behavior is ideal for

parsing log files where multiple entries of interest may occur.


2. In the context of Python file operations, what is the primary advantage of using a ‘with’

statement when opening a file?

A. It automatically converts the file contents into a dictionary.


B. It optimizes the read speed by loading the file into cache.


C. It ensures the file is properly closed even if an exception is raised.

,D. It prevents other users from reading the file simultaneously.


Correct Answer: C


Explanation: The ‘with’ statement serves as a context manager that streamlines resource

management. By using this construct, the file’s close() method is invoked automatically at

the end of the block. This prevents resource leaks and file corruption issues that occur

when a program crashes before a manual close operation.


3. Which standard library module provides tools for manipulating the system’s path and

interacting with the underlying operating system files and directories?

A. sys


B. os


C. math


D. re


Correct Answer: B


Explanation: The ‘os’ module is the standard interface for interacting with the operating

system in Python. It allows developers to perform tasks such as creating directories, listing

files, and modifying environment variables. While ‘sys’ provides access to variables used by

the interpreter, ‘os’ is essential for file-system level automation.


4. A developer needs to convert a Python dictionary into a JSON-formatted string to send

over a network. Which method from the ‘json’ module is most appropriate?

A. json.dumps()

, B. json.dump()


C. json.loads()


D. json.load()


Correct Answer: A


Explanation: The ‘json.dumps()’ function stands for ‘dump string’ and is used to serialize a

Python object into a JSON formatted string. Conversely, ‘json.dump()’ is used to write JSON

directly to a file-like object. Using the correct serialization method is crucial for data

interchange between heterogeneous systems in IT automation.


5. What will be the output of the following code snippet?


list1 = [1, 2, 3] list2 = list1 list2.append(4) print(list1)


A. [1, 2, 3, 4]


B. [1, 2, 3]


C. Error: List is immutable


D. [1, 2, 3, [4]]


Correct Answer: A


Explanation: In Python, assigning one list to another variable does not create a copy;

instead, it creates a new reference to the same list object in memory. Because lists are

mutable, any operation performed on ‘list2’ directly impacts the object referenced by ‘list1’.

To create an independent list, one should use the copy() method or slicing syntax.

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