我正在尝试获取abs
的float
,它最初存储在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中不是常规的,但是看起来,要浮动的字符串是正确的,比如从here或here。不确定,这里出了什么问题。你知道吗
不能添加
float
值和str
值;必须先将abs
函数的结果显式转换回str
,然后再向其添加空格。你知道吗相关问题 更多 >
编程相关推荐