Learn with diagrams, code, systems and practical examples.
Lists
Store an ordered, changeable collection of values.
Lists are a natural choice when order matters and you may add, remove, or update items.
Start with the idea
A list holds values in order. Positions are zero-based indexes, and common operations include append, remove, slicing, and iteration.
Small working example
Run this example first. Do not change several things at once; confirm the basic behavior, then experiment.
tasks = ["email", "deploy"]
tasks.append("review")
print(tasks[0])
print(tasks) A list holds values in order. Positions are zero-based indexes, and common operations include append, remove, slicing, and iteration.
- Lists preserve order.
- Lists are mutable.
- Indexes start at zero.
email
['email', 'deploy', 'review']The example is intentionally small. Focus on the chapter’s main idea before adding extra syntax or framework code.
Common beginner mistake
Using an index without checking whether the list has that position.
Prefer iteration when you need every item, and validate indexes when positions come from external input.
Quick recap
- Lists preserve order.
- Lists are mutable.
- Indexes start at zero.
Try it yourself
These are deliberately small. If you can complete them without copying the example, you are ready to continue.
- Add and remove an item.
- Print the first and last items safely.