Home > Article > Backend Development > 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!