[PYTHON] range and xrange

There seems to be xrange in python2 series

Simple call

import time

start = time.time()
for x in range(10000):
    pass
print "range : {}".format(time.time - start)

start = time.time()
for x in range(10000):
    pass
print "range : {}".format(time.time - start)

result

range  : 0.00071907043457
xrange : 0.000457048416138

xrange calls fast

Recommended Posts

range and xrange
python> link> range () / xrange ()
range
python> from six.moves import xrange> Six: Python 2 and 3 compatibility library> python2: xrange () / python3: range ()
About _ and __
Specifying the range of ruby and python arrays