Computer Science
STR = "RGBCOLOR"
colors = list(STR)
How do we delete 'B' in given List colors?
- del colors[2]
- colors.remove("B")
- colors.pop(2)
- All of these
Answer
All 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'.
Related Questions
What will be the output of the following?
print("ComputerScience".split("er", 2))- ["Computer", "Science"]
- ["Comput", "Science"]
- ["Comput", "erScience"]
- ["Comput", "er", "Science"]
What is the ASCII equivalent decimal no. for 'Y'?
- 87
- 88
- 89
- 90
Which of the following will give "Simon" as output?
str1 = "Hari,Simon,Vinod"- print(str1[-7:-12])
- print(str1[-11:-7])
- print(str1[-11:-6])
- print(str1[-7:-11])
Assertion(A): S1 ='CoMPuter SciENce'
S1[0] = S1[0].lower()The above code will generate error.
Reasoning(R): String is immutable by default. The contents of the string cannot be changed after it has been created.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.