@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.

People also ask

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
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 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
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.
🌐
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...
🌐
Reddit
reddit.com › r/learnpython › initializing a variable, handling exceptions and the difference between typeerror and valueerror
r/learnpython on Reddit: Initializing a variable, handling exceptions and the difference between TypeError and ValueError
March 25, 2025 - That's what it means to be a "dynamically typed" language, like Python is. However, the compiler I’m using whenever putting in an incorrect data type is raising a ValueError exception · Yes; you'll probably have to catch the ValueError and raise a TypeError.
Find elsewhere
🌐
Middleware
middleware.io › blog › python-error-types
Python Error Types: Common Errors and How to Handle Them
2. Calling a function with the wrong argument type · def square(number): return number * number print(square("4")) You can’t multiply two strings. A ValueError occurs when a function receives a value that is different from the argument type.
🌐
YouTube
youtube.com › watch
ValueErrors & TypeErrors in Python | How to tell them apart! - YouTube
Here's how to tell the difference between TypeErrors and ValueErrors in Python.My Full OOP Course:https://www.udemy.com/course/object-oriented-programming-in...
Published: March 28, 2025
🌐
Sololearn
sololearn.com › en › Discuss › 2497149 › what-is-the-difference-between-typeerror-and-valueerror
What is the difference between 'TypeError' and 'ValueError'? | Sololearn: Learn to code for FREE!
A Value error is Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value the float function can take a string, ie float('5'), it's just that the value 'string' in float('string') is an inappropriate (non-convertible) string On the other hand, Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError ...
🌐
Reddit
reddit.com › r/learnpython › im new to python and trying to fix an type error, can u help?
r/learnpython on Reddit: Im new to python and trying to fix an type error, can u help?
December 5, 2024 -

TypeError: object.__init__() takes exactly one argument (the instance to initialize)

The code i think you'll need

class Object(pygame.sprite.Sprite):
    def __init__(self, x, y, width, height, name=None):
        super().__init__()
        self.rect = pygame.Rect(x, y, width, height)
        self.image = pygame.surface((width, height), pygame.SRCALPHA)
        self.width = width
        self.height = height
        self.name = name

def draw(self, win):
        win.blit(self.image, (self.rect.x, self.rect.y))


class Block(object):
    def __init__(self, x, y, size):
        super().__init__(x, y, size, size)
        block = get_block(size)
        self.image.blit(block, (0, 0))
        self.mask = pygame.mask.from_surface(self.image)
🌐
Python Forum
python-forum.io › thread-28486.html
Type Error or Value Error?
print(int('100.0'))it is type error, how is it value error?
🌐
Scaler
scaler.com › home › topics › python valueerror
Python ValueError - Scaler Topics
December 15, 2022 - In Python, a ValueError occurs ... is most common in mathematical operations. A TypeError, as opposed to a ValueError, is raised when an operation is performed that is using an incorrect or unsupported object type....
🌐
Treehouse
ecs.teamtreehouse.com › community › valueerror-vs-typeerror
ValueError vs TypeError (Example) | Treehouse Community
February 26, 2026 - Eva Feng is having issues with: I find it a bit confusing to distinguish between ValueError and TypeError. For example, when you have float( a string ) - it shows up as ValueEr...
🌐
Reddit
reddit.com › r/learnpython › why am i receiving a valueerror here
r/learnpython on Reddit: Why am I receiving a ValueError here
February 23, 2022 -

I'm getting a value error on function 2 (is_list_odd) but not on function 1 (is_list_even) why is that? I isolate the functions and function one run fine but function 2 returns a ValueError every time, why?

def is_list_even(check_even):
    user_input = int(input())
    for i in range(user_input):
        user_num = int(input())
        check_even.append(user_num)
        if check_even[i] % 2 == 0:
            return True


def is_list_odd(check_odd):
    user_input2 = int(input())
    for j in range(user_input2):
        user_num2 = int(input())
        check_odd.append(user_num2)
        if check_odd[j] % 2 != 0:
            return True


if __name__ == '__main__':
    check_even = []
    check_odd = []
    if is_list_even(check_even):
        print('all even')
    if is_list_odd(check_odd):
        print('all odd')
    else:
        print('not even or odd')

#I don't understand why
🌐
Reddit
reddit.com › r/python › python errors as values: comparing useful patterns from rust and go
r/Python on Reddit: Python errors as values: Comparing useful patterns from Rust and Go
November 9, 2023 - Python errors as values: Comparing useful patterns from Rust and Go · r/hypeurls • · r/hypeurls · OFFICIAL COMMUNITY OF HYPEURLS.COM: r/hypeurls is a Reddit community for sharing and discussing new tech articles. Hype URLs tracks trending tech articles. Visit https://hypeurls.com to see the full list, updated every minute. Members · inngest · upvote · Can someone explain AttributeError, TypeError and ValueError ·
🌐
Carleton University
cs.carleton.edu › cs_comps › 1213 › pylearn › final_results › encyclopedia › valueError.html
Error Encyclopedia | Value Error
In Python, a value is the information that is stored within a certain object. To encounter a ValueError in Python means that is a problem with the content of the object you tried to assign the value to.
🌐
Turing
turing.com › kb › valueerror-in-python-and-how-to-fix
What is ValueError in Python & How to fix it
When a user calls a function with an invalid value but a valid argument, Python raises ValueError. Even though the value is the correct argument, it typically happens in mathematical processes that call for a specific kind of value.