HOWTO · Python

How to Start a for Loop at 1 in Python

Learn how to count from 1 with range(), number items from 1 with enumerate(), and skip the first item with slicing in Python. Use range() for numeric loop values, enumerate() for display numbering, and slicing to select items; Python list indexes remain zero-based.

On this page

To make a Python loop count from 1 through a number n, use range(1, n + 1). Python’s range() includes its start and stops before its stop value, so adding 1 includes n. This changes the numbers produced by the loop; it does not change the indexes of a list. If you want to number items for display or skip the first item, use enumerate() or a slice instead. The examples in this candidate were executed, and their behavior is supported by the supplied runtime results.

Use range() to start a numeric loop at 1

Give range() a start of 1 and a stop one greater than the final number. For example, this loop counts from 1 through 5:

n = 5
for number in range(1, n + 1):
    print(number)
1
2
3
4
5

The first argument is the starting number, and the second is the exclusive stop. Therefore, range(1, 6) produces 1, 2, 3, 4, and 5. For a different final number, replace n; for a different starting number, replace 1. You can also provide a third argument for the step, as in range(1, n + 1, 2) to count by twos. A custom helper that wraps range() can package this adjustment for reuse, but it is unnecessary for a single loop. A generator expression that adds 1 to each value is another possible way to produce adjusted values, though direct range() expresses this counting task more clearly.

Use enumerate() to number items from 1

When processing items and showing each item’s position to a reader, use enumerate(items, start=1). It yields a number and the corresponding item on each iteration:

items = ["a", "b", "c"]
for number, item in enumerate(items, start=1):
    print(number, item)
1 a
2 b
3 c

Here number takes the display values 1, 2, and 3 while item takes each list value. The start=1 argument changes the numbers yielded by enumerate(); it does not change the list’s actual indexes, which still begin at 0. This pattern is useful for numbered output, such as listing names or presenting rows with human-friendly ordinals. If you also need to access an item by its Python index, remember that the display number is one greater than that index; keep the two concepts separate in your code.

Use slicing when you want to skip the first item

If the task is to process everything after the first list value, iterate over the slice items[1:]:

items = ["header", "first", "second"]
for item in items[1:]:
    print(item)
first
second

The slice starts at index 1, so this loop visits "first" and "second" and leaves the original list unchanged. Slicing does not assign new numbers to those values; it simply selects which values the loop receives. For a list, the slice is a new list containing references to the selected items. Use this approach when the first value is a heading or otherwise should not be processed, rather than when you need to count or number every item.

Choose the method that matches your task

Use range(1, n + 1) when the loop itself must produce numeric values beginning at 1 and ending at n. Use enumerate(items, start=1) when you want to visit every item and display 1-based numbering alongside it. Use items[1:] when you want to omit the first item from iteration. These techniques solve different tasks: changing generated numbers, numbering items for presentation, and selecting a portion of a collection.

With a step of 1, set the exclusive stop to one more than the final integer to include it. With another step, the progression must land on the intended final value, and the exclusive stop must be beyond it in the direction of travel; adding 1 is not a general inclusion rule. Python list indexes remain zero-based even when enumerate() supplies a 1-based display number. Choose the simplest form that matches the result you need, and keep the numeric loop value, display number, and list index distinct when adapting the examples.