Home  >  Article  >  Backend Development  >  Python enumerate traverses array applications

Python enumerate traverses array applications

巴扎黑
巴扎黑Original
2017-05-21 10:57:331999browse

Python code for traversing arrays

In other languages, such as C#, the way we usually traverse arrays is:

for (int i = 0; i < list.Length; i++)
##{
// todo with list[i]
}

In Python, we are used to this Traversal:


for item in sequence:
process(item)

This way If the item serial number i cannot be obtained during traversal, the following traversal method is available:


for index in range(len(sequence)):
process(sequence[index])

In fact, if you know the built-in enumerate function, you can also write like this:

for index, item in enumerate(sequence):
    process(index, item)

The above is the detailed content of Python enumerate traverses array applications. 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