+ 1

What is the diffrence between range()and x range() function?

explain detail with one example?

18th Dec 2017, 4:38 PM
lokesh reddy
lokesh reddy - avatar
3 Respostas
+ 6
Note that Aditya's excellent answer applies to Python2 only. In Python 3, range() works more like xrange() in Python2.
18th Dec 2017, 6:35 PM
Eric Blinkidu
Eric Blinkidu - avatar
+ 1
xrange is an another generator, so: lst_obj = range(3) = [0,1,2] #array of 3 integers is stored in memory gen_obj = xrange(3) # this is a generator, you don't have any values, they are computed during for-loop -> next iteration means "give (compute) me last_value ++". It doesn't mean "take from a big array next value". That's why, it's so better for memory: >>> xrange(int(1e15)) xrange(1000000000000000) >>> range(int(1e15)) Traceback (most recent call last): File "<stdin>", line 1, in <module> MemoryError A great explanaition of them is here: http://stackoverflow.com/questio...
18th Dec 2017, 5:11 PM
Aditya Jha
Aditya Jha - avatar
0
tnq for giving the ans..adithya jha,and please give one example.
20th Dec 2017, 2:27 PM
lokesh reddy
lokesh reddy - avatar