This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Tuples and Sets, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
Which type is an immutable sequence?
Answer: tuple
Why: A tuple cannot be changed after it is created.
What does len(set([1, 1, 2, 3])) return?
Answer: 3
Why: The set keeps only the distinct values 1, 2, and 3.
What is name, price = item called?
Answer: Unpacking
Why: Unpacking assigns each value in the tuple to a separate name.
Which operator tests membership in a set?
Answer: in
Why: The in operator returns True when the value is present.
Complete the tuple so its second value is 5.
point = (3, ____)
print(point[1])Answer: 5
Why: Tuple values are separated by commas inside parentheses.
Complete the unpacking assignment.
point = (3, 5)
x, y = ____
print(x + y)Answer: point
Why: The names on the left receive the values from the tuple on the right.
Complete the call that removes duplicate orders.
orders = ["latte", "tea", "latte"]
unique = ____(orders)
print(len(unique))Answer: set
Why: set(orders) creates a collection of unique values.
Complete the operator that finds values in both sets.
a = {1, 2, 3}
b = {3, 4}
common = a ____ b
print(common)Answer: &
Why: The & operator returns the intersection of two sets.
What does the program output?
print(len(set("banana")))Answer: 3
Why: The distinct characters are b, a, and n.
What appears on the screen?
print((2, 3)[1])Answer: 3
Why: Index 1 is the second value of the tuple.
What is printed?
print(sorted({3, 1, 2}))Answer: [1, 2, 3]
Why: Sorting the set produces a predictable list.
What is the output?
print(2 in {1, 2, 3})Answer: True
Why: 2 is present in the set, so membership is True.
Try the questions first
Open the practice page for Python Tuples and Sets and answer the same 12 questions with instant feedback.