【python】 针对list的for循环

针对list的for循环两种方式,当时由于没搞懂range,导致使用了range(list1)错误方式,特此记录一下

 

  方法1    in直接读取list

1 list1 = ["abc","tello","hello","syou"]
2 
3 for i in list1:
4     print(i)

 

方法2  使用range

list1 = ["abc","tello","hello","syou"]

for i  in range(0,len(list1)):
     print(list[i])

 

          

posted @ 2020-04-22 15:07  qsx_suzy  阅读(8659)  评论(0编辑  收藏  举报