How to use a decimal range() step value?

前端 未结 30 2172
醉话见心
醉话见心 2020-11-21 22:34

Is there a way to step between 0 and 1 by 0.1?

I thought I could do it like the following, but it failed:

for i in range(0, 1, 0.1):
    print i
         


        
30条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 23:04

    It can be done using Numpy library. arange() function allows steps in float. But, it returns a numpy array which can be converted to list using tolist() for our convenience.

    for i in np.arange(0, 1, 0.1).tolist():
       print i
    

提交回复
热议问题