Enumerations – Basics, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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.
PREVIOUS · MODULE 56OOP – Inheritance (basic)
YOU ARE HERE · MODULE 57Enumerations – Basics
NEXT · MODULE 58Enumerations – Practical Use
What students will learn in this module
Every question in Module 57
Quick questions
- What is a tuple?AAn immutable ordered sequenceBA mutable list
- How do you create a tuple?AParentheses () or commasBSquare brackets []
- Can you change a tuple's items?AYesBNo tuples are immutable
- t = (1, 2, 3)\nt[0] returns?A1B(1)
- How do you create a single-item tuple?A(1)B(1,) with a trailing comma
Key terms
Students type the meaning of:
TupleImmutable(1,)Unpacking
Match the pairs
t = (1)Match it to what it doest[0] = 5Match it to what it doest = (1, 2, 3)Match it to what it doesa, b = (10, 20)Match it to what it does(1, 2, 3)[1]Match it to what it doeslen((4, 5, 6, 7))Match it to what it doesFill in the blanks
point = (3, 4) print(point[_])
single = (42_) # single-item tuple
a, b = (10, 20) print(_)
t = (1, 2, 3) print(___(t))
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')
