python中的enumerate获取迭代元素的下标

以前迭代的时候,需要获取次数都是如下格式:

index=1
for node in nodes:
   if index==3:
          continue
   print(node.text_content())
index+=1

  通过for循环外层定义一个变量来进行循环,然后内部进行++操作。

 

然后今天才发现还有一个迭代同时获取元素下标的属性   如下

for i ,row in enumerate(rows):
    print("现在是第几个数{}了".format(i))

  

posted @ 2018-02-28 14:16  公众号python学习开发  阅读(1161)  评论(0编辑  收藏  举报