Python enumerate() function

(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!

The enumerate()  function takes an iterable and returns an enumerate object (an iterator) that produces a tuple of the form (index, value), where index refers to the offset of the item and item refers to the corresponding item from the iterable.

The syntax of enumerate() function is as follows:


iterable(required) Any iterable object like string, list, dictionary, etc.
start(optional) Initial value of the index. It defaults to 0.

Here is an example:

The following listing shows how enumerate() works with a list, dictionary and tuple:

Setting the initial value of the index

To set the initial value of the index, we use the start keyword argument.


Other Tutorials (Sponsors)

This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *