python 3浮点数

时间:2018-01-06 20:28:58

标签: python floating-point sum

  • 0.15
  • 0.98
  • 0.92

我上面有来自mongodb的浮动数字,并尝试用下面的代码加总数字并得到错误。

 unsupported operand type(s) for +: 'int' and 'str' 

错误:     NPM_CONFIG_PRODUCTION=false

1 个答案:

答案 0 :(得分:0)

document['Price']显然包含字符串和数字的混合。您应该首先将所有元素转换为数字。

Price = [float(x) for x in document['Price']]