Files
freeCodeCamp/guide/english/python/enumerate/index.md
chris13888 fe2d44a6ad Create overview for Python's enumerate function (#23852)
* Rename guide/english/python/index.md to guide/english/python/enumerate/index.md

* Created More Info section
2018-12-19 01:38:27 -05:00

30 lines
900 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Python's Enumerate Function
---
## Overview
`enumerate()` is a built-in function in Python. It is useful for iteration over a list or any other iterable.
## Arguments
`enumerate()` requires an iterable, and `start` as an optional parameter (it defines where the indexing starts).
## Return Value
Returns an enumerate object. If you call `list()` on it, you can see that each item in the object is a tuple an index followed by the item in the iterable.
## Usage Example
animals = ['cat', 'dog', 'rabbit', 'fox', 'wolf'] # A list of animals.
for index, item in enumerate(animals, start=20):
print(index, item)
### Output
20 cat
21 dog
22 rabbit
23 fox
24 wolf
<a href='https://repl.it/repls/DarksalmonMajesticDecagons'>Try it out!</a>
#### More Information
- <a href='https://docs.python.org/3/library/functions.html#enumerate'>Python's Docs</a>