How to use a decimal range() step value?

前端 未结 30 2773
醉话见心
醉话见心 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条回答
  •  猫巷女王i
    2020-11-21 23:29

    My answer is similar to others using map(), without need of NumPy, and without using lambda (though you could). To get a list of float values from 0.0 to t_max in steps of dt:

    def xdt(n):
        return dt*float(n)
    tlist  = map(xdt, range(int(t_max/dt)+1))
    

提交回复
热议问题