Python range function

后端 未结 6 947
广开言路
广开言路 2021-02-07 05:53

Say I want to loop from 0 to 100 but with a step of 1/2. If you try

for i in range(0, 100, 0.5):
    whatever
         


        
6条回答
  •  醉梦人生
    2021-02-07 06:43

    If you have numpy, here are two ways to do it:

    numpy.arange(0, 100, 0.5)
    
    numpy.linspace(0, 100, 200, endpoint=False)
    

提交回复
热议问题