Python for loop index starts at 1 | Example code

Using the slicing method [start:] we can easily skip the first index 0 and start a for-loop at index 1 in Python. It will skip the first element in the loop.

Python for loop index starts at 1 example

Simple example code starting a for loop at index 1 skips the first index 0. Element b will not print because its index value is 0.

a_list = ["a", "b", "c"]

for item in a_list[1:]:
    print(item)

Output:

Python for loop index starts at 1

Python for loop starts at index with enumerate

If you want to start from 1 instead of 0. This method will not skip the first content just starting indexing at 1.

items = ["a", "b", "c"]

for count, item in enumerate(items, start=1):
    print(count, item)

Output:

1 a
2 b
3 c

Do comment if you have any doubts and suggestions on this Python for loop topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.