python 遍歷數組的方法


python 遍歷數組有兩種方法,一種是使用for in 來遍歷數組,一種是先獲得數組的長度,然后根據索引號遍歷數組,同時輸出索引號。

for in 遍歷數組方法:

colours = ["red","green","blue"]

for colour in colours:
    print colour

red
green
blue

遍歷數組方法二:

colours = ["red","green","blue"]
 
for i in range(0, len(colours)):
    print i, colour[i]
 
0 red
1 green
2 blue


免責聲明!

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



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