Computer science · Grades 7–10
Python lists and sequence tracing
Python lists use zero-based indexing; these tasks use the displayed list only.
Understand the idea
Read the index
Python lists use zero-based indexing; these tasks use the displayed list only.
Track mutation
An operation can change the existing list rather than create a new value.
Trace without running
Write each intermediate state before deciding the output.
Worked examples
In Python, values = [5, 8, 13]. What is values[1]?
Index 1 refers to the second item.
8
In Python, len([2, 4, 6, 8]) returns what number?
Len counts the four items.
4
Try it yourself
Trace Python: a = [3, 7]; a.append(9). What is a[2]?
For Python a = [4, 5, 6], what is a[0:2]?
- [6]
- [4, 5]
- [4, 5, 6]
- [5, 6]
For Python a = [10, 20, 30], what is a[-1]?
Why does a[3] fail for a = [8, 9, 10] in Python?
Answers and marking notes
Answers and marking notes
- 9
Append places 9 at the end, at index 2.
- [4, 5]
The start is included and the stop is excluded.
- 30
A negative index of −1 selects the last element.
- The valid nonnegative indices are 0, 1 and 2, so index 3 is out of range.
Credit zero-based indexing and the boundary.
Further reading and review references
These are reference links, not copied exercises, institutional endorsement or proof of independent review.
Preview material · independent educational review required. Grade bands are approximate, not official curriculum alignment.