Use range
.
(使用range
。)
In Python 2.x it returns a list so all you need is: (在Python 2.x中它返回一个列表,所以你需要的只是:)
>>> range(11, 17)
[11, 12, 13, 14, 15, 16]
In Python 3.x range
is a iterator.
(在Python中,3.x range
是一个迭代器。)
So, you need to convert it to a list: (因此,您需要将其转换为列表:)
>>> list(range(11, 17))
[11, 12, 13, 14, 15, 16]
Note : The second number is exclusive.
(注意 :第二个数字是独占的。)
So, here it needs to be 16+1
= 17
(所以,这里需要16+1
= 17
)
EDIT:
(编辑:)
To respond to the question about incrementing by 0.5
, the easiest option would probably be to use numpy
's arange
,
(要回答关于递增0.5
的问题,最简单的选择可能是使用numpy
的arange
,)
>>> 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])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…