CBSE Class 11 Computer Science
Question 4 of 19
Strings in Python — Question 15
Back to all questionsAll of these
Reason — The statement STR = "RGBCOLOR" assigns the string "RGBCOLOR" to the variable STR, and colors = list(STR) converts this string into a list of its individual characters. As a result, colors will be ['R', 'G', 'B', 'C', 'O', 'L', 'O', 'R']. All of the methods mentioned can be used to delete 'B' from the list colors. Using del colors[2] removes the item at index 2, which is 'B'. The colors.remove("B") method removes the first occurrence of the value 'B'. Similarly, colors.pop(2) removes and returns the item at index 2, which is 'B'.