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

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))

  

相关文章:

  • 2021-08-07
  • 2021-10-12
  • 2021-12-03
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案