xrange(stop) xrange(start, stop[, step])
Here are some examples.
xrange to generate 0 to N-1
Note that xrange does not return a list.
a = xrange(10) print "type=%s" % (type(a)) print a print "==outcome of for loop===" for i in xrange(10): print i
xrange with start, stop
This generates sequence from start to stop-1
for i in xrange(5,10): print i
xrange with start, stop, step
This generates sequence start, start+step,… Ntoe that outcome will not include stop.
for i in xrange(5,10, 3): print i
Note that if you are working on large data then it would be more memory efficient to use xrange than range.