初級 › TypeError: can only concatenate str (not "int") to str の原因と直し方 › パターン1
TypeError: can only concatenate str (not "int") to str の原因と直し方
文字列と数値を + で連結しようとしたときに出るエラーです。
1 age = 20 2 print("Age: " + ________) ^
Traceback (most recent call last):
File "main.py", line 2, in <module>
print("Age: " + age)
~~~~~~~~^~~~~
TypeError: can only concatenate str (not "int") to str
空欄を埋めて実行を通す
+ による文字列連結は両辺が文字列でなければなりません。数値はstr()で明示的に変換します。
次の問題