Arrays? (Or lists if you prefer)

Fredrik Lundh fredrik at pythonware.com
Mon Oct 23 02:56:43 EDT 2006


Hakusa at gmail.com wrote:

> What's the difference between xrange and range?

range() creates a list object and fills it in up front, xrange() returns 
a sequence-like object that generates indexes on demand.

for short loops, this difference doesn't really matter.  for large 
loops, or if you usually don't run the loop until the end, xrange()
can be more efficient.  xrange() also lets you do things like:

     for x in xrange(sys.maxint):
         ...
         if some condition:
             break

without running out of memory.

</F>




More information about the Python-list mailing list