Python ValueError

ValueError is a built-in exception in Python that is raised when a function or operation receives an argument that has the right type but an inappropriate value. For example, if you try to convert a string to an integer using the int() function, but the string contains non-numeric characters, a ValueError will be raised.

Here’s an example.



ValueError                                Traceback (most recent call last)
Cell In[5], line 1
----> 1 int('hello')

ValueError: invalid literal for int() with base 10: 'hello'

In this case, the string 'hello' is not a valid integer, so a ValueError is raised.

The following tutorials cover some of the common ValueErrors in Python and how to resolve them with the help of some examples.

Scroll to Top