October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Python for Loop with an Index: Using enumerate(), start, and Common Pitfalls

Use Python’s enumerate() to loop over an item and its position together. Learn how its default count, start=1, and item offsets differ.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use enumerate() when a Python loop needs both an item and its position: for index, item in enumerate(items):. It counts from 0 by default; use enumerate(items, start=1) for one-based labels. The start value changes the counter, not which items the loop visits.

Get each item and its index with enumerate()

enumerate(iterable, start=0) produces pairs containing a count and each value yielded by the iterable. In a for loop, unpack those two parts into separate variables:

names = ["Ada", "Grace", "Linus"]

for index, name in enumerate(names):
    print(index, name)

This prints:

0 Ada
1 Grace
2 Linus

The first variable receives the count; the second receives the item. Give the item variable a useful name, such as name, row, or item. Python’s tutorial describes enumerate() as a way to retrieve a sequence’s position and corresponding value together (Python tutorial: Looping Techniques).

Use start=1 for one-based labels

By default, the count begins at 0. To number output for people starting at 1, pass start=1:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
names = ["Ada", "Grace", "Linus"]

for number, name in enumerate(names, start=1):
    print(number, name)

The output is:

1 Ada
2 Grace
3 Linus

Here, number is a one-based label, not the item’s conventional zero-based sequence index. A descriptive name can prevent confusion when the value is for display, such as line_number or number. The built-in reference documents the signature enumerate(iterable, start=0) and explains that the counter begins at start while values are obtained from the iterable (Python built-in functions: enumerate()).

Does start=1 skip the first item?

No. start initializes the count; it does not select an item offset. enumerate(items, start=1) still visits the first item and labels it 1. The documented equivalent initializes a counter to start and then iterates over the iterable, which is why changing the count does not skip values (Python built-in functions: enumerate()).

If you need to begin at a later item, change the iterable being looped over—for example, use a slice for a sequence:

for index, item in enumerate(items[2:], start=2):
    print(index, item)

This example starts with the third item of a sliceable sequence and labels it with its original zero-based position. Slicing creates a separate slice; for other iterable types, choose an appropriate iterator operation instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the loop that matches what you need

Need Use Example
Only the values A value-only loop for item in items:
Each value and its zero-based position enumerate() with its default start for index, item in enumerate(items):
Each value and a one-based display label enumerate() with start=1 for number, item in enumerate(items, start=1):
Iteration beginning at a later item Adjust the iterable, separately from the counter enumerate(items[2:], start=2) for a sliceable sequence

If the loop never uses the position, a plain value-only loop is simpler. Use enumerate() when both the count and item are useful; it avoids maintaining a separate counter by hand.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common enumerate() mistakes

  • Expecting start to skip values: It changes the first count only. Adjust the iterable when the loop should begin later.
  • Unpacking the wrong shape: Each iteration yields a count and an item. Unpack them into two variables, or bind the pair to one variable if you need it as a pair.
  • Using a manual counter without a reason: A separate counter requires updating and maintaining extra state. Prefer enumerate() when you need both the count and the value.
  • Getting an index when you only need an item: Use for item in items: if the position is irrelevant.
  • Calling a one-based label an index: When you pass start=1, the count is useful for numbering, but it is not the usual zero-based position.

For iterable mutation or other behavior specific to a collection, consult that iterable’s documentation; enumerate() supplies counts alongside values but does not by itself establish general mutation guarantees.

Python documentation

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.