方法1,常用方法,通过for in遍历数组
复制代码 代码示例:
colours = ["red","green","blue"]
for colour in colours:
print colour
# red
# green
# blue
方法2,先获得数组的长度,然后根据索引号遍历数组,同时输出索引号。
复制代码 代码示例:
colours = ["red","green","blue"]
for i in range(0, len(colours)):
print i, colour[i]
# 0 red
# 1 green
# 2 blue