Answer key · 12 questions

Python Tuples and Sets Exercises With Answers

All 12 questions for Python Tuples and Sets in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

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.

01 · Multiple choice

Which type is an immutable sequence?

  1. list
  2. tuplecorrect
  3. dict
  4. set

Answer: tuple

Why: A tuple cannot be changed after it is created.

02 · Multiple choice

What does len(set([1, 1, 2, 3])) return?

  1. 3correct
  2. 4
  3. 2
  4. 1

Answer: 3

Why: The set keeps only the distinct values 1, 2, and 3.

03 · Multiple choice

What is name, price = item called?

  1. Joining
  2. Sorting
  3. Unpackingcorrect
  4. Slicing

Answer: Unpacking

Why: Unpacking assigns each value in the tuple to a separate name.

04 · Multiple choice

Which operator tests membership in a set?

  1. incorrect
  2. +
  3. &
  4. ==

Answer: in

Why: The in operator returns True when the value is present.

05 · Fill in the blank

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.

06 · Fill in the blank

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.

07 · Fill in the blank

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.

08 · Fill in the blank

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.

09 · Predict output

What does the program output?

print(len(set("banana")))

Answer: 3

Why: The distinct characters are b, a, and n.

10 · Predict output

What appears on the screen?

print((2, 3)[1])

Answer: 3

Why: Index 1 is the second value of the tuple.

11 · Predict output

What is printed?

print(sorted({3, 1, 2}))

Answer: [1, 2, 3]

Why: Sorting the set produces a predictable list.

12 · Predict output

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.

Practice this lesson