Code Fix

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

空欄を埋めて実行を通す

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

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

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

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

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