enumerate 函数用于遍历序列中的元素以及它们的下标 for i,v in enumerate(['tic','tac','toe']): print i,v #0 tic #1 tac #2 toe for i,j in enumerate(('a','b','c')): print i,j #0 a #1 b #2 c for i,j in enumerate({'a':1,'b':2}): print i,j #0 a #1 b 遍历字典的key和value knights={'ga
以前迭代的时候,需要获取次数都是如下格式: 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))