Functions in Python, range() and xrange() are used to iterate in a for loop for a fixed number of times. Functionality-wise, both these functions are the same. The difference comes when talking about Python version support for these functions and their return values.
range() Method
xrange() Method
In Python 3, xrange() is not supported; instead, the range() function is used to iterate in for loops
The xrange() function is used in Python 2 to iterate in for loops
It returns a list
It returns a generator object as it doesn’t really generate a static list at the run time
It takes more memory as it keeps the entire list of iterating numbers in memory
It takes less memory as it keeps only one number at a time in memory