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)
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)
Do comment if you have any doubts and suggestions on this Python for loop topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.