← Back to Error Guide
ValueError

How to Fix ValueError

Understanding and resolving ValueError in Python

What is ValueError?

A ValueError is raised when a function receives an argument of the correct data type but an inappropriate or invalid value.

Common Causes

Common causes of this error...

How to Fix

Wrong Code

# Code that causes the error
age = int('twenty-five')

Correct Code

# Fixed code
try:
    age = int('25')
except ValueError:
    print('Please enter a valid number.')

More Python Error Guides