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

 

          


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM