← Python

Lists – Indexing

Square bracket notation accesses a list item by its zero-based integer index

What it does: Unlike strings, list items can be changed by assigning to their index. -1 always gives the last element of a list. Index 0 is always the first item. Indices go from 0 to len-1 — [3] doesn't exist in a 3-item list. in checks if the value exists anywhere in the list. for...in is the standard way to iterate through a list. Assigning to nums[1] replaces the item at index 1 (the second item). The loop goes through items in order — 1 is first.

Common mistakes: List has indices 0,1,2: index 3 is out of range. Use square brackets [] for indexing, not parentheses ().

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
colors = ['red','blue','green']\ncolors[0] returns?
'red''blue'
Matches
❌ nums = [10, 20, 30] print(nums[3])
Error: Index 3 out of range
Applying
Meanings
Term
list[0]
Meaning
Access the first item in the list.
Practice
colors = ['red', 'blue', 'green']
Testing
Gaps
print(colors[])
Check Answer
Spots
2first = colors[0]
3last = colors[3]

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

The 'Nautilus' badge — Default Expert, 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. colors = ['red','blue','green']\ncolors[0] returns?
A. 'red' ✓
B. 'blue'
Index 0 is always the first item
2. colors = ['red','blue','green']\ncolors[-1] returns?
A. 'red'
B. 'green' ✓
[-1] is always the last item in a list or string
3. Can you change a list item by index?
A. Yes lists are mutable ✓
B. No lists are immutable
Unlike strings, lists are mutable — you can assign new values by index
4. nums = [10,20,30]\nnums[3] does what?
A. Returns 30
B. IndexError ✓
Indices go from 0 to len-1 — [3] doesn't exist in a 3-item list
5. 'cat' in ['cat','dog'] returns?
A. True ✓
B. False
in checks if the value exists anywhere in the list

Match the Pairs

nums = [10, 20, 30] print(nums[3]) Error: Index 3 out of range
nums = [1, 2, 3] print(nums(0)) Error: Use [] not () for indexing
nums = [5, 10, 15] nums[1] = 99 Valid: Lists are mutable
nums[-1] Ok: Last item in list
c = ['r','g','b'] print(c[0]) Output: r
c = ['r','g','b'] print(c[-1]) Output: b

Key Term

list[0]
Access the first item in the list.~~list[-1]

Fill in the Blanks

1. colors = ['red', 'blue'] print(colors[0])
2. nums = [10, 20, 30] nums[1] = 99
3. pets = ['cat', 'dog'] print('cat' in pets)
4. for fruit in fruits: print(fruit)
5. colors = ['red', 'blue', 'green'] print(colors[-1])

Spot the Error

Question 1
A colors = ['red', 'blue', 'green']
B first = colors[0]
C last = colors[3]
D print(first, last)
Line C — List has indices 0,1,2: index 3 is out of range
Question 2
A colors = ['red', 'blue']
B first = colors(0)
C print('First:', first)
D print('Done')
Line B — Use square brackets [] for indexing, not parentheses ()
Question 3
A colors = ['red', 'blue']
B first = colors['0']
C print('First:', first)
D print('Done')
Line B — Index must be an integer, not a string
Question 4
A nums = [10, 20, 30]
B nums(1) = 99
C print('Updated:', nums)
D print('Done')
Line B — Use square brackets for assignment: nums[1] = 99
Question 5
A colors = ['red', 'blue']
B for color in colors
C print(color)
D print('Done')
Line B — Missing colon after the for statement
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?