+ 1
What is the diffrence between range()and x range() function?
explain detail with one example?
3 Antworten
+ 6
Note that Aditya's excellent answer applies to Python2 only. In Python 3, range() works more like xrange() in Python2.
+ 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...
0
tnq for giving the ans..adithya jha,and please give one example.