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
| 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