Python enumerate is a built-in function that can be used to iterate through lists and tuples. It returns the index and item in the list as well as their position in the sequence.
It is a data structure that will iterate through the sequence of numbers one number at a time. It can be used to produce an iterator that can be used for loops, so they are helpful when you need to process all the elements of a list or other iterable object.
Many times, we need to keep track of the number of iterations. Python has a built-in function to count the iterations.
This article will guide you on using Python’s enumerate () function, with examples of its usage.
Table of Contents
How to use Python Enumerate() Function?
Python Enumerate() method adds a counter to an iterable and returns it as an enumerating object. This enumerated object can then be used directly for loops or converted into a list of tuples using the list() method.
This function is used within a loop to assign an index of the current loop iteration to the iterator of the loop.
Python Enumerate( ) Syntax
enumerate(iterable, start=0)
- Iterable is the object that is used for iteration, and
- The start is the counter start, which is by default 0.
Note
If enumerate object is created (i.e., calling a function with a parameter), then the first argument after the function call will hold this new object; the following arguments will start from zero as an index on every iterable start from zero. The empty tuple will be returned if no iterable has been passed as a parameter.
Python Enumerate( ) Example
CodeLeaks= ['python', 'javascript', 'java', 'linux']
enumerateCodeLeaks = enumerate(CodeLeaks)
print(list(enumerateCodeLeaks))
enumerateCodeLeaks = enumerate(CodeLeaks, 100)
print(list(enumerateCodeLeaks))
Output

How to use Python Enumerate Object in Loops?
CodeLeaks= ['python', 'javascript', 'java', 'linux']
for element in enumerate(CodeLeaks):
print(element)
print('\n')
for count, element in enumerate(CodeLeaks, 10):
print(count, element)
print('\n')
for count,element in enumerate(CodeLeaks, 100):
print(count)
print(element)
Output

Conclusion
In this article, we’ve discussed Python enumerate and how you can use it to iterate through lists. We hope you enjoyed reading this article on Python Enumerate as much as we did writing it for you. Have a great day!