pythonloopsrangepython-2.xxrange

What is the difference between range and xrange functions in Python 2.X?


Apparently xrange is faster but I have no idea why it's faster (and no proof besides the anecdotal so far that it is faster) or what besides that is different about

for i in range(0, 20):
for i in xrange(0, 20):

Solution

  • In Python 2.x:

    In Python 3: