StudyBrixFree worksheets, study guides and courses

Computer science · Grades 7–10

Python lists and sequence tracing

Python lists use zero-based indexing; these tasks use the displayed list only.

Make a worksheet

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

  1. Trace Python: a = [3, 7]; a.append(9). What is a[2]?

  2. For Python a = [4, 5, 6], what is a[0:2]?

    1. [6]
    2. [4, 5]
    3. [4, 5, 6]
    4. [5, 6]
  3. For Python a = [10, 20, 30], what is a[-1]?

  4. Why does a[3] fail for a = [8, 9, 10] in Python?

Answers and marking notes

Answers and marking notes
  1. 9

    Append places 9 at the end, at index 2.

  2. [4, 5]

    The start is included and the stop is excluded.

  3. 30

    A negative index of −1 selects the last element.

  4. 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.