Common Python Errors
Common Python Errors
by Boxplot Analytics
Sep 1, 2019
This post is updated as appropriate, so keep checking back!
Table of Contents
Errors when installing python with homebrew
Errors when writing/running python code
Check out this article for help: https://github.com/Homebrew/homebrew-core/issues/19286
Check out this article for help: https://stackoverflow.com/questions/13354207/how-to-symlink-python-in-homebrew
Writing Python Code
This means one of a few things:
Did you forget to put something in quotes? Remember if you didn’t define something as a variable, list, dictionary, etc. previously, and it’s not a number, it needs to be in quotes!
There are several types of indentation errors. These are pretty self-explanatory. You either forgot an indent or have too many. Remember, python considers indents to be four spaces or a tab, exactly.
This could mean a lot of things, but basically you aren’t following one of the basic syntax rules of Python. Here are some common examples:
- That you are trying to combine data types that aren’t compatible. You can’t concatenate a string and an integer for example.
- You’re trying to perform some operation on the wrong datatype for that function.
- Forgetting the parens around the arguments to print
- Forgetting the colon at the end of the condition in an if statement, or in a for loop
- Trying to use a reserved word as a variable name
- Code like:
if my_variable = 8: (should be == 8 when in an IF statement!)
Typically this means you are trying to access an item in a list that doesn’t exist. For example, :
flowers = ["rose", "tulip", "daisy"]
print("Flowers in my garden are:", flowers, flowers, flowers)
There is no
! Remember, lists start at 0, so it should have been
flowers, flowers, flowers
These seem scary, but they are similar to the NameError, only specific to dictionaries. They are raised when a key is not found in the set of existing keys. Check for spelling and case sensitivity!
This is most commonly caused by trying to convert a bad string into a number. For example:
my_num = int("Word")
"Tables & Linking Data Structures in Excel"
"Population Mean Hypothesis Test Example"