Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中计算列表之和时发生float对象不可调用错误_Python_List_Dataframe - Fatal编程技术网

在Python中计算列表之和时发生float对象不可调用错误

在Python中计算列表之和时发生float对象不可调用错误,python,list,dataframe,Python,List,Dataframe,当我尝试添加列表元素时,它会产生以下错误 print weights print sum(weights) 我得到以下错误 [0.2, 0.2, 0.2, 0.2, 0.2] TypeError Traceback (most recent call last) <ipython-input-77-f2d5440b3427> in <module>() 1 print weights ----> 2 print sum(weights)

当我尝试添加列表元素时,它会产生以下错误

print weights
print sum(weights)
我得到以下错误

[0.2, 0.2, 0.2, 0.2, 0.2]
  TypeError Traceback (most recent call last)
<ipython-input-77-f2d5440b3427> in <module>()
      1 print weights
----> 2 print sum(weights)
      3 

 TypeError: 'float' object is not callable
[0.2,0.2,0.2,0.2,0.2]
TypeError回溯(最近一次调用上次)
在()
1打印重量
---->2打印总和(权重)
3.
TypeError:“float”对象不可调用

在上面看不见的代码中的某个地方,您正在为
sum

分配一个值,您是否有一个名为“sum”的变量?如果您这样做,它将在函数之前使用。谢谢(我的坏)sum是一个保留字。非常感谢您的帮助