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

How to loop through all arrays in python

爱喝马黛茶的安东尼
Release: 2019-06-25 17:37:04
Original
15440 people have browsed it

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template