Data structures · 10 sample answers

Python tuples: practice questions with answers.

A tuple looks like a list with parentheses, but the differences change how you unpack data, protect values, and build dictionary keys. These questions test the details beginners usually meet in real code.

39 questions in the full bank · 13 choice · 13 fill · 13 output

What this topic tests

  • Pack and unpack values, including the one-item tuple comma.
  • Predict what happens when code tries to change a tuple.
  • Use tuples where a fixed shape or a hashable key is useful.

Common mistakes

  • Writing (1) when you need a one-item tuple. The comma in (1,) is required.
  • Trying to assign to tuple[index]. Tuples do not support item assignment.
  • Assuming a tuple is always faster or always better; choose based on whether the data should change.
Sample questions

Sample questions

10

Ten representative questions from the full bank. Try each one before opening the answer.

  1. Multiple choiceq0516

    1. Ming stores a milk tea recipe ratio in a tuple. What is the biggest difference between a tuple and a list?

    1. tuples are ordered; lists are unordered
    2. tuples are immutable; lists are mutable
    3. tuples can only hold numbers
    4. lists are faster
    Show answer

    Answer

    B. tuples are immutable; lists are mutable

    Why: A tuple is ordered and immutable; a list is ordered and mutable. Ordering is shared, so immutability is the real difference.

  2. Multiple choiceq0527

    2. 🧋 What does it mean that a tuple cannot be changed?

    1. the variable cannot be reassigned
    2. the tuple's elements cannot be modified
    3. the tuple cannot be referenced
    4. a tuple can only hold numbers
    Show answer

    Answer

    B. the tuple's elements cannot be modified

    Why: Immutability means the contents cannot be modified in place; the name can still be rebound. The tuple's identity and length are fixed.

  3. Multiple choiceq0530

    3. 🧋 What is the type of (42,)?

    1. tuple
    2. int
    3. str
    4. list
    Show answer

    Answer

    A. tuple

    Why: The comma after 42 makes this a one-element tuple, so type() reports tuple; this is the smallest legal tuple. Its length is 1.

  4. Multiple choiceq0541

    4. Which method counts how often a value appears in a tuple?

    1. count
    2. index
    3. find
    4. len
    Show answer

    Answer

    A. count

    Why: count(value) is available on tuples and returns the number of equal elements. index gives a position, find belongs to strings, and len counts everything.

  5. Fill in the blankq0518

    5. Ming splits the tuple (name, price) = ("milk tea", 15) into two variables. Which tuple mechanism is this?

    Show answer

    Answer

    unpacking

    Why: The right side packs two values and the left side unpacks them position by position. This is tuple unpacking, not slicing or copying.

  6. Fill in the blankq0534

    6. 🧋 Swap variables with tuple unpacking: a, b = ___

    Show answer

    Answer

    b, a

    Why: The right side is evaluated first, building the tuple (b, a), then it is unpacked back into a and b. That swaps the values without a temporary.

  7. Fill in the blankq0546

    7. Which standard-library factory creates a lightweight tuple with named fields?

    from collections import ____
    Point = namedtuple('Point', ['x', 'y'])
    Show answer

    Answer

    namedtuple

    Why: namedtuple builds a tuple subclass whose fields can also be read by name, so point.x works alongside point[0]. It is still a tuple, hence immutable.

  8. Output predictionq0517

    8. What is printed after unpacking and tuple addition?

    t = (1, 2, 3)
    a, b, c = t
    print(b, t + (4,))
    Show answer

    Answer

    2 (1, 2, 3, 4)

    Why: Unpacking binds 1, 2, 3 to a, b, c in order, so b is 2; adding (4,) returns a new tuple (1, 2, 3, 4) without touching t. Nothing is mutated anywhere.

  9. Output predictionq0525

    9. Read the code and write the output.

    for i, ch in enumerate("ab"):
        print(i, ch)
    Show answer

    Answer

    0 a
    1 b

    Why: enumerate yields (index, character) pairs, and print separates them with a space, so the output is 0 a then 1 b. The index starts at 0.

  10. Output predictionq0538

    10. Read the inner tuple's first element. What is printed?

    t = (1, (2, 3))
    print(t[1][0])
    Show answer

    Answer

    2

    Why: t[1] returns the inner tuple (2, 3), and [0] then takes its first element, so 2 is printed. Chained indexing walks one level at a time.

Common questions

Why does a one-item tuple need a comma?

Parentheses group an expression; the comma creates the tuple. (1) is just the integer 1, while (1,) is a tuple.

Can a tuple contain a list?

Yes. The tuple cannot be reassigned, but a mutable object inside it can still change.

Keep the streak going.

The full bank keeps your place in this browser, filters by topic, and includes a daily question and mistake review.

Open full practice