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 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?

my_colors=[ red, blue, purple, yellow, white ]
Joshua Tiedtke
Joshua Tiedtke
5,647 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

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...]