Python Python Basics (2015) Python Data Types List Creation

Karma Lama
Karma Lama
849 Points

list creation... what am i missing here?

colors = [red, green, yellow, brown , black]

lists.py
colors = [red, green, yellow, brown , black]

2 Answers

Nicholas Grenwalt
Nicholas Grenwalt
46,619 Points

In Python words are represented as strings so they must be wrapped in single (') or double (") quotes. So for each of the colors in your list, make sure that they are surrounded with quotes so that they will be correctly read as strings within your list, i.e. 'red' or "red". Either way works.

Karma Lama
Karma Lama
849 Points

Thanks for the explanation... I tried doing

colors = ["red, green , yellow, brown, black"]

now I know, I need to put quotes in every single color... thanks again!

Manish Giri
Manish Giri
16,006 Points

It's generally a good habit to try and spend some time debugging your code, in case of errors. If there are any error messages shown, that's a good starting point.

If I run your code, I get this error - NameError: name 'red' is not defined. This should tell you what's wrong, red should be a string, with quotes -"red". Same goes for the remaining colors.

Karma Lama
Karma Lama
849 Points

Thanks.....again!