In Python 2.x:
-
rangecreates a list, so if you dorange(1, 10000000)it creates a list in memory with9999999elements. -
xrangeis a sequence object that evaluates lazily.
In Python 3:
rangedoes the equivalent of Python 2’sxrange. To get the list, you have to explicitly uselist(range(...)).xrangeno longer exists.