Skip to content
Python ExceptionsError
ValueError

ValueError

A function received an argument of the right type but an inappropriate value.

python

What causes this error

The argument has the correct type but an invalid value. Common examples: int('abc'), list.remove(x) where x is not in the list, math.sqrt(-1), or unpacking the wrong number of values.

How to fix it

Validate input values before passing them to functions. Use try-except around conversions. Check that values are within expected ranges. For unpacking, ensure the number of variables matches the number of values.

Example

int("abc")  # ValueError: invalid literal for int()
Official Documentation

Related Error Codes