Enumerate() method in Python Built in Function
Enumerate method in built in function returns the enumerate object which is taken as collection in the form of lists or tuples.
Syntax:
enumerate(iterable, start=0)
Parameter
Enumerate has two parameters.
- Iterable: it supports an iterator or a sequence or an object which supports iteration.
- Start: the enumerate starts counting from a particular number. If the start parameter is omitted the default start will be taken from 0. This is an optional parameter.
Example-1:
Using list in enumerate method
x = ('apple', 'banana', 'cherry')
y = enumerate(x)
print(list(y))
Output:
Example-2:
x = ('apple', 'banana', 'cherry')
y = enumerate(x, 20)
print(list(y))
Output:
Example-3:
Use of tuple in enumerate method
x = ('apple', 'banana', 'cherry')
y = enumerate(x)
print(tuple(y))
Output:
Example-4:
breakfast = ['bread', 'milk', 'butter']
print('\n')
for count, item in enumerate(breakfast):
print(count, item)
Output:
Example-5:
breakfast = ['bread', 'milk', 'butter'] for item in enumerate(breakfast): print(item)
Output:
