总结列表中的十进制数。Python

上官林*_*官林源 0 python sum

我试图打印训练结果,但是无法总结测试精度。

q=(['0.50000', '0.56250', '0.50000', '0.50000'])

sum(q)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Run Code Online (Sandbox Code Playgroud)

Cor*_*mer 5

您有一个列表,str因此首先您必须将它们转换为float,您可以使用sum.

>>> sum(float(i) for i in q)
2.0625
Run Code Online (Sandbox Code Playgroud)