ValueError

Built-in ExceptionPython 2.0+Beginner

Raised when a function receives an argument of the right type but wrong value

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching ValueError
try:
    int("not_a_number")
except ValueError as e:
    print(f"Caught ValueError: {e}")
    print(f"Type: {type(e).__name__}")

ValueError is raised when raised when a function receives an argument of the right type but wrong value. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore