0

I want to access the first two items in the list and change it to the variable "first_two" but i can't find my mistake, please help.

Color_list = ["red", "blue", "green"] 

Color_list[0:2] 
['red', 'blue']

first_two = "red", "blue" 
Color_list[0:2] = ("first_two")  

Then it throws out like this

['f',  'i',  'r',  's',  't',  '_',  't',  'w', 'o',  'green']
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
  • Hi @ Anél Schütz , could you reformat the code inside a block-quote, between triple-backquotes? That will make it readable. Also please indicate that it is Python (or whatever language it is). THANKS! – ariels May 11 '22 at 13:19

1 Answers1

0

You can remove " around the variable name. What are you doing now is replacing first two items in Color_list with characters "f", "i", "r", "s", ...

Try:

Color_list = ["red", "blue", "green"]

first_two = "xxx", "yyy"
Color_list[0:2] = first_two  # <-- remove "

print(Color_list)

Prints:

['xxx', 'yyy', 'green']
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91