# Python – 创build2个值之间的数字列表？

``list = [11, 12, 13, 14, 15, 16]` `

` `>>> range(11, 17) [11, 12, 13, 14, 15, 16]` `

` `>>> list(range(11, 17)) [11, 12, 13, 14, 15, 16]` `

` `>>> numpy.arange(11, 17, 0.5) array([ 11. , 11.5, 12. , 12.5, 13. , 13.5, 14. , 14.5, 15. , 15.5, 16. , 16.5])` `

` `>>> x1=11 >>> x2=16 >>> range(x1, x2+1) [11, 12, 13, 14, 15, 16] >>> list1 = range(x1, x2+1) >>> list1 [11, 12, 13, 14, 15, 16]` `

` `>>> list2 = [x*0.5 for x in range(2*x1, 2*x2+1)] >>> list2 [11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0]` `

` `range(x1,x2+1)` `

` `list(range(x1,x2+1))` `

list = [x for x（x1，x2 + 1）]

` `def frange(start, stop, step=1.0): ''' "range()" like function which accept float type''' i = start while i < stop: yield i i += step # Generate one element at a time. # Preferred when you don't need all generated elements at the same time. # This will save memory. for i in frange(1.0, 2.0, 0.5): print i # Use generated element. # Generate all elements at once. # Preferred when generated list ought to be small. print list(frange(1.0, 10.0, 0.5))` `

` `1.0 1.5 [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5]` `

` `range(x,y+1) >>> range(11,17) [11, 12, 13, 14, 15, 16] >>>` `