How to make lists
Having trouble making list:
I'm using syntax to make list as:
colors = [red, orange , yellow, green , purple]
I've used with and without "" marks, still getting syntax error, I've watched video twice and not sure what I am missing to make list
colors = ["red,orange,yellow,green,purple"]
Ryan S27,264 Points
If you want to create a list of strings, you'd need to make sure that each individual item is in quotes. Once you establish that, then each item will be separated by a comma outside of the quotes.
colors = ["red", "orange", "yellow", "green", "purple"]
Your first example (the one without quotes) would work if each item in the list was a variable. But you'd need to assign a value to them first.
red = "red" orange = "orange" yellow = "yellow" green = "green" purple = "purple" colors = [red, orange, yellow, green, purple]
Your other example (the entire list of colors inside quotes) is really only creating a list with one item.
colors = ["red,orange,yellow,green,purple"] # The one item in the list is "red,orange,yellow,green,purple"
Whatever is inside a pair of quotes is considered one item, a single string. So the commas are also included in that string.
Hope this helps.