pythonerror can only concatenate str (not "int") to str

今天在使用python做一個自定義函數輸出出現報錯 : can only concatenate str (not “int”) to str
我報錯位置的源代碼:print(“直徑爲” + d + “的井蓋面積爲:” + s + “cm²”)

報錯原因:print函數中+前後的數據類型要保持一致

修改後: print(“直徑爲” + str(d) + “的井蓋面積爲:” + str(s) + “cm²”)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章