Last Updated: January 3, 2026
29 quizzes
Complete the code to create an immutable ordered collection storing three status codes.
status_codes = (200, 404, 500)Click an option to fill the blank:
Complete the code to get the third element from the tuple measurements.
third_value = measurements[]Click an option to fill the blank:
Complete the code to concatenate two tuples of coordinates into a single tuple.
all_points = first_points second_pointsClick an option to fill the blank:
Which statement about Python tuples is TRUE?
Which of the following creates a tuple with a single element 10?
Why can tuples be used as dictionary keys while lists cannot?
What is the result of this tuple operation? config = ("dev",) * 3
Given data = (10, 20, 30, 40), what does data[-2] return?
Which slicing expression returns the middle two elements of values = (1, 2, 3, 4)?
What happens in this unpacking? name, age = ("Alice", 30, "Engineer")
Given point = (3, 4), which unpacking is valid?
How do you access the field y from a named tuple Point defined as Point = namedtuple('Point', ['x', 'y'])?
Which import is correct for creating a named tuple?
Given Device = namedtuple('Device', ['name', 'ip']); d = Device('router', '10.0.0.1'), which is TRUE?
Order the steps to create a named tuple for a 2D point and use it to store coordinates.
Drag and drop to reorder, or use the arrows.
Order the steps to unpack a configuration tuple into separate variables and use one of them.
Drag and drop to reorder, or use the arrows.
What is the output of this code?
1settings = ("dark", "english", "metric")
2print(settings[0] + "-" + settings[-1])What is the output of this code?
1data = (1, 2) * 2 + (3,)
2print(len(data))What is the output of this code?
1record = ("Alice", 30, "Engineer")
2name, _, role = record
3print(role)What is the output of this code?
1from collections import namedtuple
2User = namedtuple('User', ['username', 'active'])
3u = User('bob', True)
4print(u.username, u.active)What is the output of this code?
1values = (10, 20, 30, 40)
2start, *middle, end = values
3print(middle)Find the bug in this tuple unpacking code used to handle API responses.
Click on the line(s) that contain the bug.
response = (200, 'OK')status_code, message, payload = responseprint(status_code, message)Find the bug in this code that uses a named tuple to represent a point.
Click on the line(s) that contain the bug.
from collections import namedtuplePoint = namedtuple('Point', ['x', 'y'])pt = Point(1, 2)pt.x = 10print(pt)Match each tuple-related concept with the correct description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match the tuple or named tuple usage with an appropriate example.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to safely create a dictionary using coordinate tuples as keys.
sensor_readings = {}position = sensor_readings[position] = 42.5print(sensor_readings[])Click an option to fill blank 1:
Complete the code to unpack a status tuple and log only the status text.
status = (200, 'OK', 'Success')code, , details = statusprint()Click an option to fill blank 1:
Click the line that attempts to modify an immutable tuple of coordinates.
Click on the line to select.
coords = (5, 10)coords_list = list(coords)coords_list[0] = 20coords[0] = 20print(coords)Click the line that incorrectly constructs a named tuple instance.
Click on the line to select.
from collections import namedtuplePoint = namedtuple('Point', ['x', 'y'])pt1 = Point(1, 2)pt2 = Point(x=3)print(pt1, pt2)