+ 23
What is the difference between XRANGE & RANGE...????
11 Answers
+ 21
XRANGE returns the XRANGE object while range returns the same list & uses the same memory & no matter what the range size is....
+ 14
xrange is python 2 only
range in python 3 does the same as xrange in python 2
+ 10
The only difference is that rangereturns a Python list object andxrange returns an xrange object. ... It means that xrange doesn't actually generate a static list at run-time like range does. It creates the values as you need them with a special technique called yielding.
+ 5
range vs xrange in Python
range() and xrange() are two functions that could be used to iterate a certain number of times in for loops in Python. In Python 3, there is no xrange , but the range function behaves like xrange in Python 2.If you want to write code that will run on both Python 2 and Python 3, you should use range().
range()Â â This returns a list of numbers created using range() function.
xrange() â This function returns the generator object that can be used to display numbers only by looping. Only particular range is displayed on demand and hence called âlazy evaluationâ.
Both are implemented in different ways and have different characteristics associated with them. The points of comparisons are:
Return TypeMemoryOperation UsageSpeed
Return Type
range() returns â the list as return type.
xrange() returns â xrange() object.
+ 4
Python 2:
range(a,b) = [a, b]
xrange(a,b) = [a, b)
In interval notation
+ 3
I think there is perhaps no difference in python 3 as xrange is range and range has been deprecated
+ 1
Xrange was used in older version and range is used in python 3.
+ 1
xrange is a legacy function.
It doesn't work in python 3
a = xrange(1,20)
NameError: name 'xrange' is not defined
0
XRANGE is a dynamic fact, while RANGE is simple.