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

Python enumerate traverses array applications

巴扎黑
Release: 2017-05-21 10:57:33
Original
2047 people have browsed it

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!

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