1. 程式人生 > 程式設計 >解決Python 異常TypeError: cannot concatenate 'str' and 'int' objects

解決Python 異常TypeError: cannot concatenate 'str' and 'int' objects

TypeError: cannot concatenate 'str' and 'int' objects

print str + int 的時候就會這樣了

python + 作為連線符的時候,不會自動給你把int轉換成str

補充知識:TypeError: cannot concatenate 'str' and 'list' objects和Python讀取和儲存圖片

解決Python 異常TypeError: cannot concatenate 'str' and 'int' objects

執行程式時報錯,然後我將list轉化為str就好了。

解決Python 異常TypeError: cannot concatenate 'str' and 'int' objects

利用''.join(list)

如果需要用逗號隔開,如1,2,3,4則使用','.join(list)

解決Python 異常TypeError: cannot concatenate 'str' and 'int' objects

Python中plt可以顯示和儲存圖片,不能使用mping

import matplotlib.image as mpimg # mpimg 用於讀取圖片

開頭import時加入

import matplotlib.pyplot as plt

from PIL import Image

開啟用open('路徑')

儲存用a.save('路徑')

以上這篇解決Python 異常TypeError: cannot concatenate 'str' and 'int' objects就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。