Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Adriana Alvear
Adriana Alvear
1,538 Points

Question about ValueError and TypeError

About the quiz, What is the difference between ValueError and TypeError?

1 Answer

Maxwell Newberry
Maxwell Newberry
7,693 Points

A ValueError is:

Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value

For example, if I have function that takes in a string, and requires at least three characters but I pass in a word that is two characters. This would raise a ValueError because it was passed the correct type (string), but it did not pass the an appropriate value.

A TypeError is:

Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError

For example: If my function is looking for a string argument and I pass an integer.