Python enumerate() function
The enumerate() function in Python takes a collection (e.g. a tuple) and returns it as an enumerate object.
Syntax:
1 2 3 |
enumerate(iterable, start=0) |
Parameter
Iterable: This parameter represents an iterable object
start: This parameter represents a number defining the start number of the enumerate object, and by default, its value is 0
Return
This function returns an enumerate object.
Example 1
1 2 3 4 5 6 7 |
# Python Program explaining # enumerate() function val1 = ('cat', 'dog', 'rat') val2 = enumerate(val1) print(list(val2)) |
Output
1 2 3 |
[(0, 'cat'), (1, 'dog'), (2, 'rat')] |