enumerate()

bcsamrudh's avatar
Published May 17, 2023
Contribute to Docs

The enumerate() function returns a list of tuples containing an index and an element for each of the elements in an iterator.

Syntax

enumerate(iterable)

The iterable parameter can be one of the following:

Example

The example below demonstrates how the enumerate() function is used on a list:

companies_list = ["Google","Microsoft","Amazon"]
for index,company in enumerate(companies_list):
print(f"{index}. {company}")

This will print the following output:

0. Google
1. Microsoft
2. Amazon

Codebyte Example

The following examples show how the enumerate() function is used with several iterable types:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy