Code Fix

初級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

空欄を埋めて実行を通す

広告
広告スロット(未設定)

TypeError: can only concatenate str (not "int") to str の原因と直し方

Pythonの + は両辺の型が揃っていないと使えません。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)