How To Read Common Error Messages In Python

Mallory Wilson
2 min readJun 1, 2021

When I am coding, I frequently run into error messages and sometimes I do not understand how to read them or fix the error. Here, I will discuss how to interpret three error messages that I commonly receive.

SyntaxError: invalid syntax

I always get this error and while it seems like a straightforward error to fix, I tend to have problems finding the issue in my code. Here are a few things to check for when you receive this message.

  1. If you are writing code that contains an if, if else, elif, or def statement; make sure that there is a : at the end of it.
  2. Another cause for this error message involves the = and == symbols. I have struggled to understand that == is the ‘equal to’ symbol in coding while = just gives a variable an assignment.

TypeError: Can’t convert ‘int’ object to str implicitly

First off, a type error is one that is dealing with the type of an object, meaning string, integer, or float…. When you get this message, it is saying that you must convert the variable into a string before you try and put it into something. When you get this error message, just make sure that you go back, look at all of your variables or objects, and convert them into a string if they are not already.

NameError: ‘____’ is not defined

I always seem to get this error, and it seems so simple to fix, but sometimes I can never get it to work. Here are a few reasons that I find I get this error and how to fix it.

  1. Make sure that you defined the variable before trying to use it in another line of code. For example: x = [] or x = bananas
  2. Go back and run your code from the very beginning to make sure that you actually did define your variable.
  3. Read through your line of code and make sure that you did not accidentally misspell something. (this happens to me all the time and it hard for me to catch it)

Hope this helps with your future coding!

--

--

Mallory Wilson
0 Followers

Birmingham-Southern College Student