D 522 Exam 3 V2 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 3) |
Western Governors University
1. Which module in Python is specifically designed to provide a way of using operating system
dependent functionality like reading or writing to the file system?
A. sys
B. re
C. os
D. math
Correct Answer: C
Explanation: The os module provides a portable way of using operating system dependent
functionality. This includes tasks such as manipulating file paths and listing directory
contents. It is a fundamental tool for IT automation scripts that interact with the local
environment.
2. When using the ‘re’ module, which character is used to match the start of a string?
A. ^ (Caret)
B. * (Asterisk)
C. $ (Dollar sign)
D. . (Dot)
,Correct Answer: A
Explanation: In regular expressions, the caret (^) character acts as an anchor for the
beginning of a string. This is useful when you want to ensure a specific pattern exists right
at the start of a log line. The dollar sign is used to anchor to the end of a string.
3. Which of the following is the correct way to open a file named ‘data.txt’ for writing, such
that the content is appended to the end of the file?
A. open(‘data.txt’, ‘w’)
B. open(‘data.txt’, ‘r+’)
C. open(‘data.txt’, ‘x’)
D. open(‘data.txt’, ‘a’)
Correct Answer: D
Explanation: The ‘a’ mode stands for append, which ensures that new data is added to the
end of the file without deleting existing content. The ‘w’ mode would overwrite the file
entirely, which is often undesirable in logging. The ‘r+’ mode is for both reading and writing
but starts at the beginning.
4. In the context of IT automation, what does the ‘shutil’ module primarily assist with?
A. High-level file operations like copying and archiving
B. Parsing JSON data from web APIs
C. Performing complex mathematical calculations
, D. Executing unit tests for Python code
Correct Answer: A
Explanation: The shutil module offers high-level operations on files and collections of files.
It is commonly used for copying, moving, and deleting directory trees. This makes it an
essential library for automating system backups and migrations.
5. What will the following regular expression match: [a-zA-Z]+?
A. A sequence of one or more alphabetic characters
B. Any single digit
C. Exactly one uppercase letter
D. Any character that is not a letter
Correct Answer: A
Explanation: The square brackets define a character class including all lowercase and
uppercase letters. The plus sign (+) is a quantifier meaning ‘one or more’ occurrences.
Therefore, it matches strings consisting solely of letters.
6. Which method is used to determine if a specific file exists on a disk using the os.path
module?
A. os.path.verify()
B. os.path.check()
C. os.path.isfile()
| Actual Q&A with Rationale (D522 Exam 3) |
Western Governors University
1. Which module in Python is specifically designed to provide a way of using operating system
dependent functionality like reading or writing to the file system?
A. sys
B. re
C. os
D. math
Correct Answer: C
Explanation: The os module provides a portable way of using operating system dependent
functionality. This includes tasks such as manipulating file paths and listing directory
contents. It is a fundamental tool for IT automation scripts that interact with the local
environment.
2. When using the ‘re’ module, which character is used to match the start of a string?
A. ^ (Caret)
B. * (Asterisk)
C. $ (Dollar sign)
D. . (Dot)
,Correct Answer: A
Explanation: In regular expressions, the caret (^) character acts as an anchor for the
beginning of a string. This is useful when you want to ensure a specific pattern exists right
at the start of a log line. The dollar sign is used to anchor to the end of a string.
3. Which of the following is the correct way to open a file named ‘data.txt’ for writing, such
that the content is appended to the end of the file?
A. open(‘data.txt’, ‘w’)
B. open(‘data.txt’, ‘r+’)
C. open(‘data.txt’, ‘x’)
D. open(‘data.txt’, ‘a’)
Correct Answer: D
Explanation: The ‘a’ mode stands for append, which ensures that new data is added to the
end of the file without deleting existing content. The ‘w’ mode would overwrite the file
entirely, which is often undesirable in logging. The ‘r+’ mode is for both reading and writing
but starts at the beginning.
4. In the context of IT automation, what does the ‘shutil’ module primarily assist with?
A. High-level file operations like copying and archiving
B. Parsing JSON data from web APIs
C. Performing complex mathematical calculations
, D. Executing unit tests for Python code
Correct Answer: A
Explanation: The shutil module offers high-level operations on files and collections of files.
It is commonly used for copying, moving, and deleting directory trees. This makes it an
essential library for automating system backups and migrations.
5. What will the following regular expression match: [a-zA-Z]+?
A. A sequence of one or more alphabetic characters
B. Any single digit
C. Exactly one uppercase letter
D. Any character that is not a letter
Correct Answer: A
Explanation: The square brackets define a character class including all lowercase and
uppercase letters. The plus sign (+) is a quantifier meaning ‘one or more’ occurrences.
Therefore, it matches strings consisting solely of letters.
6. Which method is used to determine if a specific file exists on a disk using the os.path
module?
A. os.path.verify()
B. os.path.check()
C. os.path.isfile()