Write Python. Understand every error.

Open the editor

Error guide · TypeError

TypeError: '>' not supported between instances of 'str' and 'int'

You compared text with a number.

Example

age = input()
if age > 17:
    print("adult")

With the program input: 18

What Python says

TypeError: '>' not supported between instances of 'str' and 'int'

As printed by Python 3.12. Other versions may word it slightly differently.

Try this code in Py-CRAFT

Why it happens

input() always returns text, even when the user types digits. Python can compare two numbers, and it can compare two pieces of text alphabetically, but it will not compare text with a number. Convert the input to a number first.

How to fix it

age = int(input())
if age > 17:
    print("adult")

Output: adult

Tips

Learn the ideas behind it

Other common errors

Share this page: