2023年7月26日发(作者:)
python遍历List集合四种⽅法这篇⽂章主要介绍了Python 列表(List) 的四种遍历⽅法实例 详解的相关资料,需要的朋友可以参考下分别是:直接遍历对象 通过索引遍历 通过enumerate⽅法 通过iter⽅法。使⽤Python遍历List四种⽅法代码如下:def text2(self): li = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v'] # 第⼀种遍历 for i in li: print(i) (2) # # 第⼆种遍历 # for i in range(len(li)): # print(i) # (1) # # 第三种种遍历 # for key,val in enumerate(li): # print(key,val) # (2) # 第四种遍历 for i in iter(li): print(i) (1)
发布者:admin,转转请注明出处:http://www.yc00.com/news/1690305392a329560.html
评论列表(0条)