D 522 Exam 1 V3 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 1) | Western Governors
University
1. Which module in Python is most commonly used to retrieve command-line arguments
passed to a script?
A. os
B. sys
C. subprocess
D. argparse
Answer: B
Rationale: The sys module provides access to some variables used or maintained by the
interpreter. Specifically, sys.argv is a list in Python, which contains the command-line
arguments passed to the script. This is fundamental for IT automation when scripts need to
handle dynamic input from the shell.
2. When opening a file in Python using open(‘data.txt’, ‘a’), what does the ‘a’ mode signify?
A. Append mode
B. Write mode (overwrite)
C. Read mode
,D. Binary mode
Answer: A
Rationale: The ‘a’ mode stands for append, which allows data to be added to the end of the
file without deleting existing content. If the file does not exist, Python will create a new one.
This is essential for logging tasks where historical data must be preserved.
3. What is the result of the expression 10 // 3 in Python?
A. 3.333
B. Error
C. 1
D. 3
Answer: D
Rationale: The double forward slash represents floor division in Python. It divides the first
number by the second and rounds down to the nearest whole number. This is distinct from
the single slash, which would return a floating-point result.
4. Which data type in Python is unordered, mutable, and does not allow duplicate elements?
A. List
B. Tuple
C. Set
D. Dictionary
, Answer: C
Rationale: A set is a collection which is unordered and unindexed. It is highly efficient for
membership testing and eliminating duplicate entries from other collections. Unlike lists,
sets do not maintain the order in which items were added.
5. In Python, how is a block of code defined for a function or a loop?
A. Curly braces {}
B. Keywords begin and end
C. Parentheses ()
D. Indentation
Answer: D
Rationale: Python uses indentation to indicate the scope of code blocks. This is a unique
feature compared to languages like C++ or Java that use braces. Consistent use of spaces or
tabs is mandatory for the script to execute correctly.
6. Which method is used to remove leading and trailing whitespace from a string?
A. strip()
B. clean()
C. trim()
D. remove()
Answer: A
Automation | Actual Q&A with Rationale
(D522 Exam 1) | Western Governors
University
1. Which module in Python is most commonly used to retrieve command-line arguments
passed to a script?
A. os
B. sys
C. subprocess
D. argparse
Answer: B
Rationale: The sys module provides access to some variables used or maintained by the
interpreter. Specifically, sys.argv is a list in Python, which contains the command-line
arguments passed to the script. This is fundamental for IT automation when scripts need to
handle dynamic input from the shell.
2. When opening a file in Python using open(‘data.txt’, ‘a’), what does the ‘a’ mode signify?
A. Append mode
B. Write mode (overwrite)
C. Read mode
,D. Binary mode
Answer: A
Rationale: The ‘a’ mode stands for append, which allows data to be added to the end of the
file without deleting existing content. If the file does not exist, Python will create a new one.
This is essential for logging tasks where historical data must be preserved.
3. What is the result of the expression 10 // 3 in Python?
A. 3.333
B. Error
C. 1
D. 3
Answer: D
Rationale: The double forward slash represents floor division in Python. It divides the first
number by the second and rounds down to the nearest whole number. This is distinct from
the single slash, which would return a floating-point result.
4. Which data type in Python is unordered, mutable, and does not allow duplicate elements?
A. List
B. Tuple
C. Set
D. Dictionary
, Answer: C
Rationale: A set is a collection which is unordered and unindexed. It is highly efficient for
membership testing and eliminating duplicate entries from other collections. Unlike lists,
sets do not maintain the order in which items were added.
5. In Python, how is a block of code defined for a function or a loop?
A. Curly braces {}
B. Keywords begin and end
C. Parentheses ()
D. Indentation
Answer: D
Rationale: Python uses indentation to indicate the scope of code blocks. This is a unique
feature compared to languages like C++ or Java that use braces. Consistent use of spaces or
tabs is mandatory for the script to execute correctly.
6. Which method is used to remove leading and trailing whitespace from a string?
A. strip()
B. clean()
C. trim()
D. remove()
Answer: A