WGU D522 Python for IT Automation OA
Exam Prep
200 Questions & Answers with Rationales
SECTION 1: PYTHON FUNDAMENTALS (Questions 1-40)
Question 1
What is the output of the following code?
python
x=5
y=2
print(x // y)
A) 2.5
B) 2
C) 3
D) 2.0
Answer: B) 2
Rationale: The // operator performs floor division, which returns the integer
quotient rounded down. 5 // 2 = 2 (not 2.5). This is different from / which returns a
float.
Question 2
Which of the following is NOT a valid variable name in Python?
A) _my_var
B) myVar2
C) 2myVar
D) my_var
,Answer: C) 2myVar
Rationale: Python variable names cannot start with a number. They must start with
a letter (a-z, A-Z) or underscore (_). The subsequent characters can be letters,
numbers, or underscores.
Question 3
What is the result of bool([]) in Python?
A) True
B) False
C) Error
D) None
Answer: B) False
Rationale: In Python, empty sequences (lists, tuples, strings), empty dictionaries,
and the number 0 evaluate to False in a boolean context. [] is an empty list, so it
evaluates to False.
Question 4
Which method is used to add an element to the end of a list?
A) insert()
B) append()
C) extend()
D) add()
Answer: B) append()
Rationale: append() adds a single element to the end of a list. insert() adds at a
specific index, extend() adds multiple elements from another iterable, and add() is
not a list method (it's for sets).
Question 5
,What does the pass statement do in Python?
A) Terminates the program
B) Does nothing and acts as a placeholder
C) Skips the next iteration of a loop
D) Exits a function
Answer: B) Does nothing and acts as a placeholder
Rationale: pass is a null operation - it does nothing when executed. It's used as a
placeholder where syntax requires a statement but you don't want any action to be
taken, such as in empty function or class definitions.
Question 6
What is the output?
python
s = "Hello World"
print(s[6:])
A) "World"
B) "World "
C) "World"
D) "llo World"
Answer: A) "World"
Rationale: String slicing [start:end] extracts characters from index start to end-1.
Index 6 is 'W' (H=0, e=1, l=2, l=3, o=4, space=5, W=6), and since no end is
specified, it goes to the end of the string.
Question 7
Which operator is used for string concatenation?
A) &
B) .
,C) +
D) *
Answer: C) +
Rationale: In Python, the + operator concatenates strings. Example: "Hello" + " "
+ "World" results in "Hello World". * is used for repetition, not concatenation.
Question 8
What is the correct way to create a tuple?
A) my_tuple = [1, 2, 3]
B) my_tuple = (1, 2, 3)
C) my_tuple = {1, 2, 3}
D) my_tuple = <1, 2, 3>
Answer: B) my_tuple = (1, 2, 3)
Rationale: Tuples are created using parentheses (). Lists use square brackets [],
sets use curly braces {}, and angle brackets <> are not used for Python data
structures.
Question 9
What is the output of the following?
python
print(2 ** 3 ** 2)
A) 64
B) 512
C) 729
D) 128
Answer: B) 512
Rationale: The exponentiation operator ** has right-to-left associativity. So 2 ** 3
** 2 is evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512.
Exam Prep
200 Questions & Answers with Rationales
SECTION 1: PYTHON FUNDAMENTALS (Questions 1-40)
Question 1
What is the output of the following code?
python
x=5
y=2
print(x // y)
A) 2.5
B) 2
C) 3
D) 2.0
Answer: B) 2
Rationale: The // operator performs floor division, which returns the integer
quotient rounded down. 5 // 2 = 2 (not 2.5). This is different from / which returns a
float.
Question 2
Which of the following is NOT a valid variable name in Python?
A) _my_var
B) myVar2
C) 2myVar
D) my_var
,Answer: C) 2myVar
Rationale: Python variable names cannot start with a number. They must start with
a letter (a-z, A-Z) or underscore (_). The subsequent characters can be letters,
numbers, or underscores.
Question 3
What is the result of bool([]) in Python?
A) True
B) False
C) Error
D) None
Answer: B) False
Rationale: In Python, empty sequences (lists, tuples, strings), empty dictionaries,
and the number 0 evaluate to False in a boolean context. [] is an empty list, so it
evaluates to False.
Question 4
Which method is used to add an element to the end of a list?
A) insert()
B) append()
C) extend()
D) add()
Answer: B) append()
Rationale: append() adds a single element to the end of a list. insert() adds at a
specific index, extend() adds multiple elements from another iterable, and add() is
not a list method (it's for sets).
Question 5
,What does the pass statement do in Python?
A) Terminates the program
B) Does nothing and acts as a placeholder
C) Skips the next iteration of a loop
D) Exits a function
Answer: B) Does nothing and acts as a placeholder
Rationale: pass is a null operation - it does nothing when executed. It's used as a
placeholder where syntax requires a statement but you don't want any action to be
taken, such as in empty function or class definitions.
Question 6
What is the output?
python
s = "Hello World"
print(s[6:])
A) "World"
B) "World "
C) "World"
D) "llo World"
Answer: A) "World"
Rationale: String slicing [start:end] extracts characters from index start to end-1.
Index 6 is 'W' (H=0, e=1, l=2, l=3, o=4, space=5, W=6), and since no end is
specified, it goes to the end of the string.
Question 7
Which operator is used for string concatenation?
A) &
B) .
,C) +
D) *
Answer: C) +
Rationale: In Python, the + operator concatenates strings. Example: "Hello" + " "
+ "World" results in "Hello World". * is used for repetition, not concatenation.
Question 8
What is the correct way to create a tuple?
A) my_tuple = [1, 2, 3]
B) my_tuple = (1, 2, 3)
C) my_tuple = {1, 2, 3}
D) my_tuple = <1, 2, 3>
Answer: B) my_tuple = (1, 2, 3)
Rationale: Tuples are created using parentheses (). Lists use square brackets [],
sets use curly braces {}, and angle brackets <> are not used for Python data
structures.
Question 9
What is the output of the following?
python
print(2 ** 3 ** 2)
A) 64
B) 512
C) 729
D) 128
Answer: B) 512
Rationale: The exponentiation operator ** has right-to-left associativity. So 2 ** 3
** 2 is evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512.