python3中str到float的转换错误

2024-09-30 20:34:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取absfloat,它最初存储在str中,如下所示:

for q in range(0, len(moms), 1):
    print("mom types", type(moms[q]))
    out.write(abs(float(moms[q]))+" ")
out.write("\n")

会产生错误:

mom types <class 'str'>
Traceback (most recent call last):
  File "s2gen.py", line 192, in <module>
    out.write(abs(float(moms[q]))+" ")
TypeError: unsupported operand type(s) for +: 'float' and 'str'

我在python中不是常规的,但是看起来,要浮动的字符串是正确的,比如从herehere。不确定,这里出了什么问题。你知道吗


Tags: inforlenheretyperangeabsfloat