ValueError in Python — What It Means and How to Fix It

What Python's ValueError exception means and how to resolve it.

Published October 26, 2026

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

Key points

  • Catch it specifically with "except ValueError:" when you want to handle this exact case rather than a bare except

Example

int('abc')  # ValueError: invalid literal for int()
More Python articles