Lists: the first item has index zero
A list stores ordered items. An index is a position counted from zero, not the item’s value. len gives the item count; append adds one item to the end.
| Observation | What it means |
|---|---|
| a = [10, 20, 30] | indices 0, 1, 2 |
| len(a) = 3 | last nonnegative index is 2 |
One worked example
- a = [4, 8]Two items have indices 0 and 1.
- a.append(12)Add a third item.
- a[2]Index 2 returns the third item, which is 12.
Watch out: A list of length n has nonnegative indices from 0 to n−1. Python also supports negative indices; −1 means the last item.
Goal, prerequisites and card origin
What you will learn: Find an item by index and identify list length.
What you need first: Variables and integers.
An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1
Reference for the underlying principle ↗Show connections
A list stores ordered items. An index is a position counted from zero, not the item’s value. len gives the item count; append adds one item to the end.