Editor

Tuples: What Does This Print

What does this print? · Intermediate · about 8 min

Read each short program and type exactly what it prints, with each printed line on its own line. If a program stops with an error, type the error's name, like TypeError.

Example

t = (4, 5, 6)
print(t[1], len(t))

prints

5 3
  1. Program 1

    t = (5)
    u = (5,)
    print(type(t), type(u))
  2. Program 2

    t = (1, 2, 3)
    t[0] = 9
    print(t)
  3. Program 3

    t = (1, [2, 3])
    t[1].append(4)
    print(t)
  4. Program 4

    first, *rest = (10, 20, 30, 40)
    print(first, rest)
  5. Program 5

    a, b = 1, 2
    a, b = b, a + b
    print(a, b)
  6. Program 6

    t = (3, 1, 2)
    print(sorted(t), t)
  7. Program 7

    x, y = (1, 2, 3)
    print(x)
  8. Program 8

    points = {(0, 0): "origin"}
    print(points[(0, 0)], (1, 2) < (1, 3))