解决Python中sum函数出现的TypeError: unsupported operand type(s) for +: 'int' and 'list'错误问题

当在Python中运行sum函数时,会出现“TypeError: unsupported operand type(s) for +: 'int' and 'list'”这样的问题

代码如:

print(sum([[1, 2, 3], [4, 5, 5]]))

会出现如下的错误:

解决方法:在程序前加上导入numpy模块即可

from numpy import *

关于上述问题,我仅仅找到了这个解决方法,并不知道为什么,希望后续能够找到。如有知道的,希望能够告知,谢谢!

猜你喜欢

转载自blog.csdn.net/Sophia_11/article/details/84976687
今日推荐