enumerate()

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy