()

Module 22: Tuple Practice Zone

Exploring Tuples: Ordered, Immutable Collections. CT Concepts: Data Structures, Constraints.

Anatomy of Tuple Creation & Access

Tuples are defined with parentheses `()` and items separated by commas. They are ordered, and you access items using square brackets `[]`. Click the parts below.

point = (10, 25, "Origin")

x_coord = point[0] # Access first element

Identify all parts!

Build-a-Tuple

Drag the pieces into the dark grey area to construct a tuple: `("AI", 2024)`. Remember the parentheses and comma!

Drop tuple pieces here...

Testing Immutability

Tuples are immutable - you can't change their elements after creation. Let's simulate this! Assume we have `my_tuple = (10, 20, 30)`.
Try writing code to access the element at index 1 (value 20). Then, try writing code to change the element at index 0 to 99.

Result will appear here...

Spot the Tuple

Which of the following lines correctly define a tuple? Click the line(s) you think are tuples, then check your selection. Pay attention to parentheses `()` and commas `,`!

Tuple Mini Missions!

Apply what you've learned about tuples. Complete these small coding tasks.

Mission 1: Create a Simple Tuple

Create a tuple named `info` containing your favorite color (string) and your favorite number (integer). Then, print the `info` tuple.

Mission 2: Access an Element

Create a tuple `settings = ("High", True, 1080)`. Then, write a command to access and print only the second element (the boolean value).

Mission 3: Immutability Comment

Create a tuple `constants = (3.14, 9.8)`. On the next line, add a comment explaining why you *cannot* change the first element to `3.14159`.

Module 22 Practice Complete!

Excellent work with tuples! You've grasped their creation, access, and immutability.
Ready for a deeper challenge? Proceed to the Advanced Practice for Module 22!