'float' object cannot be interpreted as an integer如果step一定要是小数怎么办

img


代码如上图,系统报错,提示 'float' object cannot be interpreted as an integer
python循环语句里,step必须是整数吗?
如果step一定要是小数怎么办?

不是说for循环需要整数,是因为你的range里的step不能是小数

  1. 使用numpy的构造数组方法
import numpy

for i in numpy.arange(1, 16, 1.5):
    print(i)
  1. 自己写一个构造数组的方法

for循环中step一定要为整数的,step为小数可以自己写个while循环