带字符串的for循环有什么问题?(What is wrong with this for loop with a string? [closed])

编程入门 行业动态 更新时间:2024-10-10 11:25:36
带字符串的for循环有什么问题?(What is wrong with this for loop with a string? [closed]) Start= 1 End= 10 change=0.5 for Start in range(Start,End,change) : print(Start)

这段代码有什么问题? 我在学校工作,似乎无法使用字符串的for循环。

Start= 1 End= 10 change=0.5 for Start in range(Start,End,change) : print(Start)

What is wrong with this code? I was working at it in school and can't seem to use the for loop with a string.

最满意答案

Python range支持浮点increment ,因此错误:

DeprecationWarning: integer argument expected, got float

所以你在0.5的值需要是一个整数,你可以用数学来得到相同的输出

Start= 2 End= 21 change=1 for Start in range(Start,End,change) : print(Start*0.5)

Python range wont support floating point increment, Hence the error:

DeprecationWarning: integer argument expected, got float

So your value at 0.5 needs to be an integer, and you can use mathematics to still get same output

Start= 2 End= 21 change=1 for Start in range(Start,End,change) : print(Start*0.5)

更多推荐

本文发布于:2023-08-04 18:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1419239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   字符串   wrong   closed   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!