WGU D522 V2 PYTHON FOR IT
AUTOMATION FINAL EXAM STUDY
GUIDE
1. Which method is used in the ‘os’ module to change the current working directory of the
script?
A. os.path.move()
B. os.getcwd()
C. os.setdir()
D. os.chdir()
Answer: D
Conceptual Explanation: The os.chdir() function is used to change the current working
directory to a specified path.
2. When using the ‘csv’ module, which class allows you to map the information in each row to
a dictionary?
A. csv.Reader
B. csv.RowDict
,C. csv.DataMap
D. csv.DictReader
Answer: D
Conceptual Explanation: csv.DictReader creates an object that operates like a regular
reader but maps the information in each row to a dict whose keys are given by the optional
fieldnames parameter.
3. In regular expressions, which metacharacter matches the start of a string?
A. $
B. ^
C. *
D. .
Answer: B
Conceptual Explanation: The caret (^) symbol is used in regex to match the beginning of a
line or string.
4. What is the result of the expression: ‘Hello World’.split()?
A. (‘Hello’, ‘World’)
B. [‘Hello’, ‘World’]
C. ‘Hello’, ‘World’
, D. [‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ’ ‘, ’W’, ‘o’, ‘r’, ‘l’, ‘d’]
Answer: B
Conceptual Explanation: The split() method without arguments splits a string into a list of
words using whitespace as the delimiter.
5. Which subprocess function is recommended for running a command and waiting for it to
finish while capturing the output?
A. subprocess.popen()
B. subprocess.call()
C. subprocess.execute()
D. subprocess.run()
Answer: D
Conceptual Explanation: subprocess.run() is the recommended approach for invoking
subprocesses in Python 3.5+.
6. How do you access the first command-line argument passed to a script (excluding the script
name)?
A. sys.argv[0]
B. sys.args[1]
C. sys.argv[1]
D. os.argv[1]
AUTOMATION FINAL EXAM STUDY
GUIDE
1. Which method is used in the ‘os’ module to change the current working directory of the
script?
A. os.path.move()
B. os.getcwd()
C. os.setdir()
D. os.chdir()
Answer: D
Conceptual Explanation: The os.chdir() function is used to change the current working
directory to a specified path.
2. When using the ‘csv’ module, which class allows you to map the information in each row to
a dictionary?
A. csv.Reader
B. csv.RowDict
,C. csv.DataMap
D. csv.DictReader
Answer: D
Conceptual Explanation: csv.DictReader creates an object that operates like a regular
reader but maps the information in each row to a dict whose keys are given by the optional
fieldnames parameter.
3. In regular expressions, which metacharacter matches the start of a string?
A. $
B. ^
C. *
D. .
Answer: B
Conceptual Explanation: The caret (^) symbol is used in regex to match the beginning of a
line or string.
4. What is the result of the expression: ‘Hello World’.split()?
A. (‘Hello’, ‘World’)
B. [‘Hello’, ‘World’]
C. ‘Hello’, ‘World’
, D. [‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ’ ‘, ’W’, ‘o’, ‘r’, ‘l’, ‘d’]
Answer: B
Conceptual Explanation: The split() method without arguments splits a string into a list of
words using whitespace as the delimiter.
5. Which subprocess function is recommended for running a command and waiting for it to
finish while capturing the output?
A. subprocess.popen()
B. subprocess.call()
C. subprocess.execute()
D. subprocess.run()
Answer: D
Conceptual Explanation: subprocess.run() is the recommended approach for invoking
subprocesses in Python 3.5+.
6. How do you access the first command-line argument passed to a script (excluding the script
name)?
A. sys.argv[0]
B. sys.args[1]
C. sys.argv[1]
D. os.argv[1]