Python Python Basics (2015) Python Data Types List Creation

my_colors=[ red, blue, green, yellow, white ] why is a name error being shown with the first item of this list?

why is this name error being shown?

lists.py
my_colors=[ red, blue, purple, yellow, white ]
Joshua Tiedtke
Joshua Tiedtke
5,400 Points

Colors are strings so you have to write them like: "red", "blue", ...

Also your list is supposed to be called colors not my_colors.

1 Answer

Erik Krieg
MOD
Erik Krieg
Treehouse Moderator 43,037 Points

Python is interpreting all those colors as variable names, but since those variables are not defined Python is throwing an error. I suspect your intention was for the colors in the list to be strings (how text is referred to in most programming languages).

To change these from variables to strings all you need to do is wrap them in quotes, ['red', 'blue', etc...]