Home  >  Article  >  Backend Development  >  How to loop through all arrays in python

How to loop through all arrays in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-13 13:08:2915249browse

How to loop through all arrays in python

#How to iterate through all arrays in python? Here are two ways to traverse an array in Python:

#The first, the most commonly used, is to traverse the array through for in

Related Recommendation: "python video tutorial"

colours = ["red","green","blue"]
for colour in colours:
    print colour
# red
# green
# blue

The second method is to first obtain the length of the array, then traverse the array according to the index number, and output the index number at the same time

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

The above is the detailed content of How to loop through all arrays in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn