@Liam Hayes (https://teamtreehouse.com/liamhayes) Hi! I have a note about @Steven Parker (https://teamtreehouse.com/stevenparker)'s example (especially the second one). When I was trying to wrap my head around this, I could not for the life of me understand why the built-in function for changing something to an int would give a ValueError with a string as opposed to a TypeError. Surely, it's expecting a number, right? Well, no. It isn't. The int() function takes either a number or a string. It can convert the string "21" to the integer 21, but it can't convert "dog" to a number. Thus, it's getting the right type, but it's still not a value that it can convert. This is when we get the ValueError. It's of the right type, but the value is such that it still can't be done. That being said, if we tried to send in something that was neither a string nor a number, it would have generated a TypeError as it is of the wrong type. Hope this helps! :sparkles: edited for additional note In your own custom made functions, you can pass in whatever you want, although ideally, you know what you're passing in. This is not true of built-in functions in Python. When in doubt, check the documentation for the function in question. Answer from Jennifer Nordell on teamtreehouse.com
🌐
Reddit
reddit.com › r/learnpython › what's the difference between a typeerror and valueerror?
r/learnpython on Reddit: What's the difference between a TypeError and ValueError?
September 21, 2022 -

In this example:

x = int(input("x: "))
print(f'x = {x}')

if the input is a string, a ValueError is raised. Why not a TypeError? An invalid data type is inputted after all.

Top answer
1 of 2
8
@Liam Hayes (https://teamtreehouse.com/liamhayes) Hi! I have a note about @Steven Parker (https://teamtreehouse.com/stevenparker)'s example (especially the second one). When I was trying to wrap my head around this, I could not for the life of me understand why the built-in function for changing something to an int would give a ValueError with a string as opposed to a TypeError. Surely, it's expecting a number, right? Well, no. It isn't. The int() function takes either a number or a string. It can convert the string "21" to the integer 21, but it can't convert "dog" to a number. Thus, it's getting the right type, but it's still not a value that it can convert. This is when we get the ValueError. It's of the right type, but the value is such that it still can't be done. That being said, if we tried to send in something that was neither a string nor a number, it would have generated a TypeError as it is of the wrong type. Hope this helps! :sparkles: edited for additional note In your own custom made functions, you can pass in whatever you want, although ideally, you know what you're passing in. This is not true of built-in functions in Python. When in doubt, check the documentation for the function in question.
2 of 2
0
A TypeError occurs when an operation or function is applied to an object of inappropriate type. A ValueError occurs when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError. Examples: passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError. For more details, see the Exceptions page (https://docs.python.org/3/library/exceptions.html) of the Python documentation.
Discussions

Explain Python ValueError Exception Handling (With Real Examples & Best Practices)
In Python, errors during program execution are called exceptions. One of the most common built-in exceptions developers encounter is ValueError. ... A function receives an argument of the correct type, but the value itself is invalid. More on accuweb.cloud
🌐 accuweb.cloud
1
January 15, 2024
What's the difference between a TypeError and ValueError?
Just to make things clear. input("x: ") always returns a string. It can be "123" or "bananas". In the first case, it can be converted to an integer. In the second case, it cannot, and a ValueError is raised. But in either case the type is fine for the int function. So this is a value error, not a type error. More on reddit.com
🌐 r/learnpython
9
6
September 21, 2022
422 error.
422 usually means that the data that API receive is not what it expected. You should check what format you use to send the image, and if there should be other fields along with it. And as always, you would receive better help if you actually post some code, an error, or at least a screenshot. More on reddit.com
🌐 r/FastAPI
12
0
February 7, 2023
What does this error mean:"value too long for type character varying(25)"

When you define a model with a charfield, this one have a max_length option. Here, it's certainly 25 characters. So you can't send a value with more than 25 characters.

More on reddit.com
🌐 r/django
2
1
April 3, 2015
People also ask

What are common Python errors?
The most common Python errors consist of SyntaxError, NameError, TypeError, ValueError, IndexError, KeyError, and AttributeError.
🌐
middleware.io
middleware.io › blog › python-error-types
Python Error Types: Common Errors and How to Handle Them
How do I handle errors in Python?
You should use the try-except blocks and write clear error messages.
🌐
middleware.io
middleware.io › blog › python-error-types
Python Error Types: Common Errors and How to Handle Them
How can I monitor Python errors in real time?
You can use tools like Middleware to track, analyze, and fix Python errors across your application instantly.
🌐
middleware.io
middleware.io › blog › python-error-types
Python Error Types: Common Errors and How to Handle Them
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError.
🌐
Middleware
middleware.io › blog › python-error-types
Python Error Types: Common Errors and How to Handle Them
A TypeError happens when you use the wrong type (like adding a string to a number), while a ValueError happens when the type is right but the value is incorrect (like converting “abc” to an integer).
🌐
Quora
quora.com › What-is-the-difference-between-TypeError-and-ValueError-in-Python-When-does-Python-throw-these-exceptions
What is the difference between 'TypeError' and 'ValueError' in Python? When does Python throw these exceptions? - Quora
Answer: 🔴1. TypeError happens when an operation is performed on an inappropriate type. For example: Copy [code]result = 'string' + 5 # Can't add string and integer [/code]🔴2. ValueError occurs when a function gets an argument of the right type but inappropriate value. For instance: Copy [co...
Find elsewhere
🌐
Carleton University
cs.carleton.edu › cs_comps › 1213 › pylearn › final_results › encyclopedia › valueError.html
Error Encyclopedia | Value Error
To encounter a ValueError in Python means that is a problem with the content of the object you tried to assign the value to. This is not to be confused with types in Python. For instance, imagine you have a dog and you try to put it in a fish tank. This would be an example of a type error, ...
🌐
Real Python
realpython.com › ref › builtin-exceptions › valueerror
ValueError | Python’s Built-in Exceptions – Real Python
You can handle ValueError to gracefully deal with invalid input so your program doesn’t crash unexpectedly and can offer users helpful feedback. That distinction—right type, wrong value—is exactly what separates a ValueError from a TypeError.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-valueerror-exception-handling-examples
Python ValueError: Exception Handling Examples & Fixes | DigitalOcean
Learn how to handle Python ValueError exceptions with code examples, common causes, and best practices. Read the full guide to fix errors fast.
🌐
W3Schools
w3schools.com › python › ref_exception_valueerror.asp
Python ValueError Exception
Python Examples Python Compiler ... Study Plan Python Interview Q&A Python Training ... The ValueError exception occurs if a function receives a value of wrong type....
🌐
Accuweb
accuweb.cloud › home › explain python valueerror exception handling (with real examples & best practices)
Explain Python ValueError Exception Handling (With Real Examples & Best Practices)
January 15, 2024 - Python ValueError is raised when a function receives a value of the correct type but an inappropriate or invalid value. Example: Example: int(“abc”) # Raises ValueError The string is a valid type (str), but its value cannot be converted ...
🌐
Honeybadger
honeybadger.io › blog › errors-in-python
Errors in Python: Types, Causes, and Examples - Honeybadger Developer Blog
April 27, 2026 - The TypeError exceptions in Python occur when an operation is applied to a value or variable of an incompatible data type. For example, adding an integer and a string results in a TypeError exception with the error message TypeError: unsupported operand type(s) for +: 'int' and 'str', as shown below:
🌐
Scientech Easy
scientecheasy.com › home › blog › types of exception in python
Types of Exception in Python - Scientech Easy
January 29, 2026 - The ValueError exception occurs when a built-in operation or function expects an argument of correct data type but receives an inappropriate or invalid value for that operation. Look at the example below: ... def calculate_square_root(number): if number < 0: raise ValueError("ValueError: Cannot ...
🌐
Python4CSIP
python4csip.com › files › download › 016. Exception Handling in Python - Web.pdf pdf
Exception Handling in Python “Handling the runtime errors”
block which can handle any type · of runtime errors, so if try block · raises any other runtime error like · ValueError when we input invalid · data in variable a or b like string, the same message ‘Sorry you · cannot divide by zero’ will be · printed · Prepared by - Vinod Kumar ...
🌐
Home and Learn
homeandlearn.uk › python-error-checking.html
Python Error Checking
This type of error this is called a ValueError. You normally see it when Python has a problem with the numbers you enter. Our ValueError was because we tried to convert the string 'one' to an integer. The string was coming from the input box. We didn't check to see if it was a digit or not, ...
🌐
Studentrobotics
studentrobotics.org › docs › troubleshooting › python
Python Troubleshooting | Student Robotics
If you forget to indent some code, or mix tabs and spaces, you will get an indentation error. For example: ... Variables in Python not only have a value, but also a type. This might be a string (some characters), an integer (whole number), a float (number with a decimal point), a robot (your ...
🌐
Luke Plant
lukeplant.me.uk › blog › posts › raising-exceptions-or-returning-error-objects-in-python
Raising exceptions or returning error objects in Python - lukeplant.me.uk
June 6, 2022 - But even in Python, which doesn’t have that built in, I think there are some compelling advantages: We expect the calling code to handle all the different return values at some point, and at the same point. (This is unlike some code where we can raise an exception that we never expect the calling code to specifically handle – it will be handled by more generic methods at a different layer). It therefore makes sense that we treat all 3 values as the same kind of thing — they are just different return values.
🌐
Shishirkant
shishirkant.com › python-errors
Python Errors – Shishir Kant Singh
>>> ‘2’+2 Traceback (most recent call last): File “<pyshell#23>”, line 1, in <module> ‘2’+2 TypeError: must be str, not int · ValueError is thrown when a function’s argument is of an inappropriate type.
🌐
Milliams
milliams.com › courses › intermediate_python › Exceptions.html
Errors and Exceptions - Intermediate Python
Traceback (most recent call last): File "/home/matt/courses/intermediate_python/recipe.py", line 4, in <module> weight_in_grams = convert.ounces_to_grams(-30) File "/home/matt/courses/intermediate_python/convert.py", line 4, in ounces_to_grams raise ValueError("Cannot convert negative mass") ValueError: Cannot convert negative mass · This means that we cannot accidentally ignore the error and use the erroneous value.