Enumerations – Basics, online

Six activities your students do on their own devices. See who's finished, and their scores.

Enumerations – Basics in one minute

What students need to know

Tuples are ordered, immutable sequences defined with parentheses. Tuple unpacking assigns each value to a variable in order.

Tuples are like lists but cannot be changed after creation. The comma makes it a tuple — (1,) is a tuple, (1) is just parentheses around 1.

Mistakes students make

  • Tuples are immutable: can't change items. Create a new tuple instead.
  • Tuples don't have append(): they're immutable.
  • (42) is just the number 42. Need trailing comma: (42,) for a tuple.
  • 3 values but only 2 variables: need matching count for unpacking.

Discover other journeys with this module

What students will learn in this module

Every question in Module 57

Quick questions

  1. What is a tuple?AAn immutable ordered sequenceBA mutable list
  2. How do you create a tuple?AParentheses () or commasBSquare brackets []
  3. Can you change a tuple's items?AYesBNo tuples are immutable
  4. t = (1, 2, 3)\nt[0] returns?A1B(1)
  5. How do you create a single-item tuple?A(1)B(1,) with a trailing comma

Key terms

Students type the meaning of:

  • Tuple
  • Immutable
  • (1,)
  • Unpacking

Match the pairs

t = (1)Match it to what it does
t[0] = 5Match it to what it does
t = (1, 2, 3)Match it to what it does
a, b = (10, 20)Match it to what it does
(1, 2, 3)[1]Match it to what it does
len((4, 5, 6, 7))Match it to what it does

Fill in the blanks

  1. point = (3, 4)
    print(point[_])
  2. single = (42_)  # single-item tuple
  3. a, b = (10, 20)
    print(_)
  4. t = (1, 2, 3)
    print(___(t))
  5. print(2 __ (1, 2, 3))

Spot the error

Question 1

At = (1, 2, 3)Bt[0] = 99Cprint('Updated:', t)Dprint('Done')

Question 2

At = (1, 2, 3)Bt.append(4)Cprint('Tuple:', t)Dprint('Done')

Question 3

Asingle = (42)Bprint('Type:', type(single))Cprint('Value:', single)D# expects tuple

Question 4

Acoords = (1, 2, 3)Ba, b = coordsCprint('a:', a, 'b:', b)Dprint('Done')

Question 5

At = (1, 2, 3)Bfirst = t(0)Cprint('First:', first)Dprint('Done')