>>> for x in xrange(5):
print x
0
1
2
3
4
Tip: You can substitute the range statement for the xrange statement. However, xrange will normally be more efficient than range, especially if you are iterating over a large range of numbers.
See also
Starting the Python shell
Printing hello world
Using basic variables
Creating an array and a dictionary and printing values
Looping through a predefined list