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