tasks = ["read"]
tasks.append("practice")Line-by-line explanation
- The first line creates a one-item list.
tasks.appendselects the list’s append method.- The method adds practice to the end.
tasks.remove("read")Line-by-line explanation
removesearches for the value read.- That first matching item is deleted.
- The list now contains only practice.
pop() removes and returns an item by index. Assignment can replace an existing item.
tasks[0] = "review"Line-by-line explanation
- Index 0 selects the first item.
=replaces that position.- The list now contains review.
Tiny Practice
Add milk to the shopping list.
Starter template
items = ["bread"]
CHANGE_ME
print(items)Line-by-line explanation
- The first line creates the list.
- The missing line should change it.
Hint
- Use
append. - Call it with a dot.
- Put milk in quotes.
Show Solution
items = ["bread"]
items.append("milk")
print(items)Line-by-line explanation
- The list starts with bread.
- Append adds milk at the end.
- Print displays both items.