Back
+10 XP
Concept

Getting Indexes with enumerate()

Need both the index number and the item simultaneously? Use `enumerate()`:

python
podium = ["Neo", "Trinity", "Morpheus"]
for rank, player in enumerate(podium, start=1):
    print(f"#{rank}: {player}")

# 63. Getting Indexes with enumerate() Need both the index number and the item simultaneously? Use `enumerate()`: ```python podium = ["Neo", "Trinity", "Morpheus"] for rank, player in enumerate(podium, start=1): print(f"#{rank}: {player}") ``` `start=1` lets you count human-style without doing `rank + 1` arithmetic everywhere.

Checkpoint

What does `enumerate(items)` hand you on each loop turn?

Practice

Loop over `tasks = ["Wake up", "Code", "Sleep"]` with `enumerate(tasks, start=1)` and print each step number with its task name.

Terminal
01
Tap code blocks below to assemble
Available Blocks