Indexes with enumerate1 / 4
CRASH COURSE
Indexes with enumerate
enumerate produces an index and item together, avoiding manual counters. By default indexing starts at zero.
- Pass start=1 for human-friendly numbering. The underlying collection does not change.
- Use for position, item in enumerate(items) to unpack each pair. This keeps the loop readable and avoids repeated indexing.
for position, item in enumerate(["tea", "water"], start=1):
print(position, item)