Concept
Accessing & Modifying List Items
Lists are zero-indexed: the first item is `[0]`. You can directly overwrite any item by assigning to its index.
python
fruits = ["apple", "banana"]
print(fruits[0]) # apple
fruits[1] = "cherry" # replaces banana
print(fruits) # ['apple', 'cherry']
# 67. Accessing & Modifying List Items Lists are zero-indexed: the first item is `[0]`. You can directly overwrite any item by assigning to its index: ```python fruits = ["apple", "banana"] print(fruits[0]) # apple fruits[1] = "cherry" # replaces banana print(fruits) # ['apple', 'cherry'] ``` Try to access an index that doesn't exist (like `fruits[99]`) and Python crashes with an `IndexError`.
Checkpoint
What is the index of the very first element in a Python list?
Practice
Change the first item of `scores = [10, 20, 30]` to `99`, then print `scores`.
01
Tap code blocks below to assemble
Available Blocks