A moderately useful type built into Python, which neatly encapsulates the arithmetic sequence for loop, favoured by many programming languages. An xrange is an iterator, so you can loop over it with, e.g., a for command. In contrast to the outwardly similar range function, which returns a list of values, an xrange object only ever remembers its construction arguments and current value, saving considerably on memory for long loops.

xrange(x) (for an integer x) will iterate over the values 0, 1, ..., x-1. Thus, for i in xrange(x): print f(x) will print out the results of calculating f(0), f(1), up to f(x-1).

More completely, xrange(start, end, skip) (with any numeric arguments, not just integers) creates an iterable object, the iterator of which which iterates over 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.

Log in or registerto write something here or to contact authors.