Python write xlsx encounter enumerate

Don't talk nonsense, just go ahead!

Official introduction: The enumerate() function is used to combine a traversable data object (such as a list, tuple or string) into an index sequence, and list data and data subscripts at the same time. It is generally used in a for loop.

So I found this introduction again

enumerate(iteration, start): returns an enumerated object. Iterator (iteration) must be another iteration object that can be supported. The initial value is zero by default, that is, if you do not enter start, it means starting from zero. The input of the iterator can be a list, a string, a collection, etc., because these are the objects of the class iteration. Returns an object. If you express it in the form of a list, it is a list. Each element of the list is a tuple. The ancestor has two elements. The first element represents the number, which is the meaning of the first element. The second element is the corresponding element of the iterator, which is when the default start is zero. If it is not zero, it means that the first element of the first tuple of the list is the value of start, and the following elements are added in sequence, and the second element still means the same.

b = [1,2,3,4,5,6,7,8,9]

for i , item in enumerate(b):
       print(i, item)


result

0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9

Process finished with exit code 0

Guess you like

Origin blog.csdn.net/weixin_37254196/article/details/108573208