Parts of an Error Message

Challenge 5-1: Debugging

Errors

Parts of an Error Message

Fixing Errors

Now let’s take a look at that error message and see what it’s really telling us.

>>> "friend" + 5

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: Can't convert 'int' object to str implicitly

The first two lines are pretty common to all error messages, so they won’t really help us much here. But the last line gives us some valuable information.

  • int is an integer

  • str is a string

  • Python cannot concatenate objects of different types (see Challenge 1-3 if you need a refresher on concatenation)

We tried to concatenate two pieces of data (which Python calls objects) - the string "friend" and the number 5. But Python isn’t able to concatenate those two objects because one is a string and one is an integer. They're two different types of data. And so we get what’s called a "TypeError".

When Python sees an expression like this, it doesn't know if we're trying to add numbers or concatenate strings. And Python is not smart enough to guess what we mean - we have to tell it. So with this error, Python is letting us know that it needs clarification.