python in enumeratee () function study notes

1, personal understanding:

the enumerate () objects (such as lists, strings, tuples etc.) function to return a form to be similar iterative dictionary: (index, element), wherein the position index for the element. 
Used for counting obtained in a for loop, the method may be used simultaneously if necessary index and value elements.

2, the syntax:

the enumerate (Iterable [, Start]) 
Iterable: iterables 
start: the starting index, the default reference numerals from 0 to

3, the return value

Returns a enumerate object (enumeration object), into each element of each such (index, element) in the form

4. Examples

A = [ ' H ' , ' E ' , ' L ' , ' L ' , ' O ' ]
 Print (the enumerate (A))
 Print (List (the enumerate (A))) 
output:
 <the enumerate Object AT 0x000002367B41A3F0> 
[ (0, ' H ' ), (. 1, ' E ' ), (2, ' L ' ), (. 3, ' L ' ), (. 4, ' O ')] 
First described the function returns a print enumerate type and stored in the memory 0x000002367B41A3F0
a=['H','e','l','l','o']
for data in enumerate(a):
    print(data)
for index,element in enumerate(a):
    print(index,element)
输出结果:
(0, 'H')
(1, 'e')
(2, 'l')
(3, 'l')
(4, 'o')
0 H
1 e
2 l
3 l
4 o
  • The second method is to call general use, you can get indexed directly.

Guess you like

Origin www.cnblogs.com/Ycc-LearningRate/p/11869332.html