This enumerate()
function returns an enumerated object adding counters to the iterable.
enumerate(*iterable, start=0*)
Here,
Note:
>>> # without start value specified
>>> list1 = ['information', 'technology', 'pvt.', 'Ltd.']
>>> enumlist1 = enumerate(list1)
>>> list(enumlist1)
[(0, 'information'), (1, 'technology'), (2, 'pvt.'), (3, 'Ltd.')]
>>> # with start value specified
>>> list1 = ['information', 'technology', 'pvt.', 'Ltd.']
>>> enumlist1 = enumerate(list1, 10)
>>> list(enumlist1)
[(10, 'information'), (11, 'technology'), (12, 'pvt.'), (13, 'Ltd.')]
for
loop>>> list1 = ['information', 'technology', 'pvt.', 'Ltd.']
>>> for i in enumerate(list1):
... print(i)
...
(0, 'information')
(1, 'technology')
(2, 'pvt.')
(3, 'Ltd.')
>>> for count, i in enumerate(list1):
... print(count, i)
...
0 information
1 technology
2 pvt.
3 Ltd.
>>> for count, i in enumerate(list1, 10):
... print(count, i)
...
10 information
11 technology
12 pvt.
13 Ltd.