Skip to Content

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.

📚 Discover Online Data Science Courses & Programs (Enroll for Free)

Introductory ⭐

Intermediate ⭐⭐⭐

Advanced ⭐⭐⭐⭐⭐

🔎 Find Data Science Programs 👨‍💻 111,889 already enrolled

Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.



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.

Upskill your career right now →