Python List Creation and Indexing
Core idea
A list stores items in an ordered sequence. Write comma-separated values inside square brackets, or [] for an empty list. Lists can contain repeated values and different types. An index starts at zero; negative indices count from the end. Unlike strings, lists are mutable: you can replace an item using assignment to its index.
Index 0 selects A and -1 selects C.
Update a measurement
Only the second slot changes; the list still has three items.
Empty list: intentional error
No index is valid in an empty list. Use len(items) to check the number of items first.
Common mistake
An index must already exist for item assignment. items[0] = 3 does not add an item to an empty list; adding items is the next lesson.
Practice
Create a list of three bus stops. Print the last stop, replace the middle stop, then print the whole list.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
List creation and indexing
Check your understanding of list creation and indexing.
What is printed?
items = [3, 9, 6]print(items[-1])What is printed?
items = [1, 2]items[0] = 5print(items)Which error occurs?
items = [1, 2]print(items[2])Which describes a list?