In Python, the built-in function range(x) returns the list [0, 1, 2, ..., x-1]. The standard idiom for looping over some index (0 to x-1) is thus for i in range(x).

Actually, range is more versatile than that. range(start, end, skip) (with any numeric arguments, not just integers) returns a list of values beginning with start, incremented by skip each time, and ending on the last value before end. skip defaults to 1. If there is just one argument, it is taken to be end, and start=0.

It is often much better to use xrange, a built-in iterator type, an instance of which which returns the same values as an iteration over a range-generated list, but never generates in memory the entire (possibly very long) list of values. The arguments to the constructor are identical.