Back to Blog
Developer guide
PYTHONJune 7, 2026

Python ValueError Examples and Fixes for Developers

When working with Python, developers often encounter ValueError exceptions, which can be frustrating and time-consuming to resolve. ValueError is a broad exception type that occurs when a function or operation receives an argument with an inappropriate value, such as an invalid date, a non-numeric input, or an out-of-range value. In this article, we'll explore common ValueError examples, their causes, and step-by-step fixes to improve your debugging skills and code reliability.

1. ValueError: Invalid Literal for Int With Base 10

This error occurs when you try to convert a non-numeric string to an integer with base 10.

Why It Happens

The most common cause is trying to convert a string that contains non-numeric characters, such as a decimal point or a letter.

How to Fix It

To fix this error, you can use the str.isdigit() method to check if the string consists only of digits before attempting to convert it to an integer.


2. ValueError: time data did not match format

This error occurs when trying to parse a string as a date using the datetime module, but the string does not match the expected format.

Why It Happens

Typically, this error happens when the date string contains extra characters or when the format is incorrect.

How to Fix It

To resolve this issue, ensure that the date string matches the specified format. You can use the strptime function with a specific format string to parse the date string correctly.


3. ValueError: not enough values to unpack

This error occurs when trying to unpack a tuple or list with fewer elements than the number of variables on the left side of the assignment.

Why It Happens

The most common cause is trying to unpack a tuple or list that has fewer elements than the number of variables in the assignment.

How to Fix It

To fix this error, you can use the * operator to capture any excess values into a list or tuple, or you can ensure that the number of variables matches the number of elements in the tuple or list.


4. ValueError: max left shift exceeded

This error occurs when trying to left shift a number by more bits than are present in the number.

Why It Happens

Typically, this error happens when trying to shift a number beyond its maximum value.

How to Fix It

To resolve this issue, you can use the bitwise operators with caution and ensure that the left shift operation does not exceed the maximum value of the number.


5. ValueError: invalid literal for long() with base 10

This error occurs when trying to convert a non-numeric string to a long integer with base 10.

Why It Happens

The most common cause is trying to convert a string that contains non-numeric characters, such as a decimal point or a letter.

How to Fix It

To fix this error, you can use the str.isdigit() method to check if the string consists only of digits before attempting to convert it to a long integer.


6. ValueError: too many values to unpack

This error occurs when trying to unpack a tuple or list with more elements than the number of variables on the left side of the assignment.

Why It Happens

Typically, this error happens when trying to unpack a tuple or list that has more elements than the number of variables in the assignment.

How to Fix It

To fix this error, you can use the * operator to capture any excess values into a list or tuple, or you can ensure that the number of variables matches the number of elements in the tuple or list.

Conclusion

In this article, we've covered common Python ValueError examples, their causes, and step-by-step fixes. By understanding these error scenarios and applying the fixes, you'll improve your debugging skills and write more reliable code. Remember to use the str.isdigit() method to check for non-numeric characters, ensure date strings match the expected format, and use the * operator to capture excess values. With practice, you'll become more proficient in handling ValueError exceptions and write more robust Python code.

Explore More Debugging Resources

- [Browse all PYTHON errors](/languages/python)

- [Browse errors by type](/error-types)

- [Search all documented errors](/search)

- [Use the Error Explainer](/error-explainer-tool)

Browse allPython errors

Related PYTHON Articles

Have a specific error? Get an instant explanation.

Explain an Error