如何更好地控制 Python 中的循环增量? [英] How do get more control over loop increments in Python?

查看:27
本文介绍了如何更好地控制 Python 中的循环增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 0.01 的步长(例如)从 0 循环到 1.我该怎么做呢?for i in range(start, stop, step) 只接受整数参数,所以浮点数不起作用.

I'm trying to loop from 0 to 1 using step sizes of 0.01 (for example). How would I go about doing this? The for i in range(start, stop, step) only takes integer arguments so floats won't work.

推荐答案

for i in [float(j) / 100 for j in range(0, 100, 1)]:
    print i

这篇关于如何更好地控制 Python 中的循环增量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆