range is a Python function for integer number
1、range(int_num),输出一个从0-(int_num-1)的list
range(10)
[0,1,2,3,4,5,6,7,8,9]
range(1,5)
1,2,3,4
3 range(start, end, steps) will product a list from start to end by steps. The list`s last element will not larger than end - 1.
range(1,6,2)
[1,3,5]
range(2,6,2)
[2,4]
1 frange(int_num) will product a list from 0 to int_num
pylab.frange(4)
[ 0. 1. 2. 3. 4.]# it`s from 0 to 4
2 frange(start, end) will product a list from start to end and the step is 1.0
print pylab.frange(1,4)
[ 1. 2. 3. 4.]
3 frange(start, end, steps) will product a list from start to end by steps.
pylab.frange(1,4,0.5)
[ 1. 1.5 2. 2.5 3. 3.5 4. ]
pylab.frange(1,4.4,0.5)
[ 1. 1.5 2. 2.5 3. 3.5 4. 4.5]
xrange is a Python function. Its use and parameters are same with range. But it is looked as a type and return an object, the object is iterable, rather than a list. It is faster and less memory than range
>>>xrange(1,3)# produce a object
xrange(1,3)
>>>x = xrange(1,3)
>>>x
xrange(1,3)
>>>x[1]
2
>>>range(1,3)# produce a list
[1,2]