初級 › TypeError: can only concatenate str (not "int") to str の原因と直し方 › パターン3
TypeError: can only concatenate str (not "int") to str の原因と直し方
文字列と数値を + で連結しようとしたときに出るエラーです。
1 x = 3 2 y = 4 3 print("sum=" + _______________) ^
Traceback (most recent call last):
File "main.py", line 3, in <module>
print("sum=" + x + y)
~~~~~~~^~~
TypeError: can only concatenate str (not "int") to str
空欄を埋めて実行を通す
計算結果を文字列と連結する場合も、計算を終えた値をstr()で変換します。
次の問題