You are currently viewing Python enumerate() Function With Example – Beginner’s Guide

Python enumerate() Function With Example – Beginner’s Guide


First of all, What is the meaning of enumerating?

The meaning of enumerating is to number or name a list of things separately.

Python enumerate() function does the same thing as its name depicts itself.

Python enumerate()

Python enumerate() function takes a collection(e.g. a list or a tuple) and returns them as an enumerated object.

The enumerate() function adds a number/count to each item of the iterable object and returns an enumerate object.

Here’s a simple example of enumerate() function usage:



The syntax of enumerate() function is:

enumerate(iterable, start=0)


iterable – must be a sequence, an iterator, or objects that supports iteration.

start – It is optional. If the start is not specified then the count will start from 0(default) else the count will start from a specified number and increment until the loop ends.


We specified the start parameter which is equal to 10 and hence the enumerated output starts from the specified number.


If we see the above example, we converted our enumerate object into the list type and then print it.

What if we don’t convert our enumerated object into a list type then what will happen?

Well, the answer is pretty simple we don’t get any enumerated object instead, we’ll get the location of an enumerating object in the memory/CPU.



Looping over enumerate() object

We can perform for loop to iterate over enumerate objects.


Performing enumerate() on

We are going to see the examples where we use the enumerate() function on different data types in Python.

String –

Python str type can be iterated so we can perform enumerate() function on it.

Example: Performing enumerate() on string


We can use start parameter also –


List –

We performed enumerate() function on list type in the example below where the first block of code gives the start value as 2 and we used a simple approach in the second block of code.

Example: Performing enumerate() on list


Tuple –

Example: Performing enumerate() on tuple


Dictionary –

dict() type contains key-value pairs, so we can enumerate() dictionary items (keys and values) separately.

Example: Performing enumerate() on dictionary


Example: Performing enumerate() on dictionary using start


Set –

set() type in Python is unordered, unchangeable, and unindexed, so when we enumerate them, the “set” item appears in random order.

Example: Performing enumerate() on set



As we discussed above, Python enumerate() function helps us to add counter to our iterable objects.

You have seen the implementation of enumerate() function on the built-in data types in Python as well as you’ve seen how you can loop over iterable objects and enumerate them.

You can use this function in many ways like enumerating the files in the particular directory to make the folder structure pretty or you can make a tool where a user can automatically number their files and folders easily or maybe something else.

That’s all for now.

Keep Coding✌✌