无法将字符串列表转换为浮点数(Can't convert a list of strings to floats)

编程入门 行业动态 更新时间:2024-10-17 11:23:54
无法将字符串列表转换为浮点数(Can't convert a list of strings to floats)

我的程序应该用一堆数字读取文本文件,并仅列出正数。 我无法将文本文档中的字符串转换为浮点数,因此我无法确定它们是否为正数。

我链接了截图,因为我的复制粘贴是错误的。

http://i.stack.imgur.com/L1Z7z.png

没有number = float(number) ,我得到['3.7', '-22', '3500', '38', '-11.993', '2200', '-1', '3400', '3400', '-3400', '-22', '12', '11', '10', '9.0']

My program is supposed to read a text document with a bunch of numbers and make a list of only the positive numbers. I can't convert the strings from the text document to a float so i can't determine if they are postive.

I linked a screenshot because my copy paste is buggy.

http://i.stack.imgur.com/L1Z7z.png

Without the number = float(number) , I get ['3.7', '-22', '3500', '38', '-11.993', '2200', '-1', '3400', '3400', '-3400', '-22', '12', '11', '10', '9.0']

更多推荐

本文发布于:2023-08-07 11:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464501.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   浮点数   列表   floats

发布评论

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

>www.elefans.com

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