1. 程式人生 > >解決Python中sum函數出現的TypeError: unsupported operand type(s) for +: 'int' and 'list'錯誤問題

解決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 *

關於上述問題,我僅僅找到了這個解決方法,並不知道為什麼,希望後續能夠找到。如有知道的,希望能夠告知,謝謝!