Python enumerate list | Example code

The Python enumerate() function adds a counter to iterable objects like a list. This method will allow you to loop over a list of items while keeping track of the index value in a separate variable.

enumerate(iterable, start=0)

The start is an optional argument for counting the index, the default value is zero.

Python enumerate list example

Simple example code use enumerate() to get a counter in a loop.

values = ["A", "B", "C"]

for count, value in enumerate(values):
    print(count, value)

Output:

Python enumerate list

Do comment if you have any doubts and suggestions on this Python enumerate 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.