Python: Iterating through an array
Articles may may have files attached at the end of the post
Submitted by chantra on Wed, 04/02/2008 - 17:43
Iterating over an the elements of an array is pretty easy to do in python with the use of a for loop.
This tutorial will explain how to iterate through an array in python through a short script.
The script below will iterate through each elements of an array and print their value:
- #!/usr/bin/env python
- # iterating through an array
- arr = ("element1", "element2", "element3")
- for i in arr:
- print i
When unning this script, the output will be:
$ ./iterate.py element1 element2 element3












