初級 › TypeError: '>' not supported between instances の原因と直し方 › パターン1
TypeError: '>' not supported between instances の原因と直し方
文字列と数値、あるいはNoneと数値など、比較できない型同士を比較しようとしたときに出るエラーです。
1 age = ____ ^ 2 if age > 18: 3 print("adult")
Traceback (most recent call last):
File "main.py", line 2, in <module>
if age > 18:
^^^^^^^^
TypeError: '>' not supported between instances of 'str' and 'int'
空欄を埋めて実行を通す
文字列と数値は大小を比較できません。入力値を数値として扱うにはint()やfloat()で変換します。
次の問題