The xrange() function is similar to range(), but instead of returning a list, it returns an iterator object that generates the numbers in the range.
Loops using xrange() are a bit faster and use less memory.
You can see Python's internal difference between range() and xrange() by comparing the following. Note that Python converts the xrange() object to an internal "equivalent":
>>> range(0, 10, 3) [0, 3, 6, 9] >>> xrange(0, 10, 3) xrange(0, 12, 3)
Was this article helpful?