Side-by-side comparison of TypeError and ValueError — understand the differences, causes, and fixes.
TypeErrorAn operation or function was applied to an object of an inappropriate type.
You performed an operation on incompatible types, such as adding a string to an integer, calling a non-callable object, passing wrong argument types, or using an object that does not support the required protocol (iteration, indexing, etc.).
Check the types of your variables with type(). Convert types explicitly: str(), int(), float(), list(). Use isinstance() for type checking. Read the error message carefully; it usually tells you exactly which types are incompatible.
ValueErrorA function received an argument of the right type but an inappropriate value.
The argument has the correct type but an invalid value. Common examples: int('abc'), list.remove(x) where x is not in the list, math.sqrt(-1), or unpacking the wrong number of values.
Validate input values before passing them to functions. Use try-except around conversions. Check that values are within expected ranges. For unpacking, ensure the number of variables matches the number of values.