← Python

Tuples – Practical Use

Tuples group related fixed values, return multiple values from a function, and can be used as dictionary keys

What it does: Using enum members makes comparisons self-documenting. Looping over an enum yields each member in definition order. An invalid enum name raises AttributeError; a mistyped string silently passes. if status == Status.ACTIVE: is clearer and safer than if status == 'active':. auto() assigns the next available integer so you don't need to number each member manually. Enum members are hashable (immutable) so they work as dict keys and set members. Use enums when you have a defined list of valid options that won't change. Size.SMALL is the key — looking it up returns the value 5.

Common mistakes: Compare with enum member, not string: prevents typos. String key typo passes silently. Enum key would cause clear error.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Why use Color.RED instead of 'red'?
Typos cause errors immediatelyIt's shorter
Matches
❌ if status = Status.ACTIVE:
Error: Use == not = for comparison
Applying
Meanings
Term
auto()
Meaning
Automatically assigns incrementing integer values to enum members.
Practice
from enum import Enum
Testing
Gaps
from enum import Enum,
Check Answer
Spots
4 INACTIVE = 2
5if status == 'active':

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Starfish' badge — Five-Point Star, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Why use Color.RED instead of 'red'?
A. Typos cause errors immediately ✓
B. It's shorter
An invalid enum name raises AttributeError; a mistyped string silently passes
2. Can enums be used in if/elif chains?
A. No
B. Yes great for state machines ✓
if status == Status.ACTIVE: is clearer and safer than if status == 'active':
3. What does auto() do?
A. Automatically assigns incrementing values ✓
B. Creates the class
auto() assigns the next available integer so you don't need to number each member manually
4. Can enums be dictionary keys?
A. No
B. Yes they are hashable ✓
Enum members are hashable (immutable) so they work as dict keys and set members
5. When should you use enums?
A. For a fixed set of choices (like status, direction, color) ✓
B. For all variables
Use enums when you have a defined list of valid options that won't change

Match the Pairs

if status = Status.ACTIVE: Error: Use == not = for comparison
for item in Status.members: Error: Use for item in Status: to iterate
if status == Status.ACTIVE: Valid: Compare enum members with ==
for item in Status: Ok: Iterate through all enum members
min(3, 1, 4, 1, 5) Output: 1
max(3, 1, 4, 1, 5) Output: 5

Key Term

auto()
Automatically assigns incrementing integer values to enum members.~~Type safety

Fill in the Blanks

1. from enum import Enum, auto class Color(Enum): RED = auto()
2. prices = {Size.SMALL: 5} print(prices[Size.SMALL])
3. if status == Status.ACTIVE: print('Active')
4. for item in Color: print(item.name)
5. class Size(Enum): SMALL = auto()

Spot the Error

Question 1
A from enum import Enum
B class Status(Enum):
C ACTIVE = 1
D INACTIVE = 2
E if status == 'active':
Line E — Compare with enum member, not string: prevents typos
Question 2
A prices = {'SMALL': 5, 'MEDIUM': 8}
B size = 'SMALL'
C cost = prices['SMAL']
D print('Cost:', cost)
Line C — String key typo passes silently. Enum key would cause clear error.
Question 3
A from enum import Enum, auto
B
C class Color(Enum):
D RED = auto
E GREEN = auto
Line D — auto needs parentheses: auto() not just auto
Question 4
A def paint(color):
B if color == 'red':
C pass
D
E paint('rad')
Line E — String 'rad' passes silently. Enum Color.RED would error immediately.
Question 5
A from enum import Enum
B class Color(Enum):
C RED = 1
D
E if color == Color.RED.value:
Line E — Compare with the member (Color.RED), not its value: loses type safety
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?