Python ValueError: meaning and fix

ValueError: The type is right, but the value is not.

Code that causes it

n = int("열")
print(n)
Open in the runner

You tried to turn text that is not a number into a number. A value from input holds spaces or letters.

Print the value before you convert it. Check it with isdigit() first.

How to fix it

n = int("10")
print(n)
Open in the runner

Why it happens

int() accepts text. The text just has to look like a number before it can be converted.

The official docs are in English. See it in the official Python docs

Back to the runnerMore errors