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!