今天在使用python做一個自定義函數輸出出現報錯 : can only concatenate str (not “int”) to str
我報錯位置的源代碼:print(“直徑爲” + d + “的井蓋面積爲:” + s + “cm²”)
報錯原因:print函數中+前後的數據類型要保持一致
修改後: print(“直徑爲” + str(d) + “的井蓋面積爲:” + str(s) + “cm²”)
今天在使用python做一個自定義函數輸出出現報錯 : can only concatenate str (not “int”) to str
我報錯位置的源代碼:print(“直徑爲” + d + “的井蓋面積爲:” + s + “cm²”)
報錯原因:print函數中+前後的數據類型要保持一致
修改後: print(“直徑爲” + str(d) + “的井蓋面積爲:” + str(s) + “cm²”)