13. Predict the output of the following python code
colors = ["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
del color[4]
colors.remove("blue")
colors.pop(3)
print(colors)
Answers
Answered by
7
Output:
['violet', 'indigo', 'green', 'red']
Answered by
7
Refer the attached image for the output.
Explanation:
Program:
#Here, colors is a object
colors = ["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
#Here, del is a keyword which is used to delete objects. The del keyword is used to delete variables and lists, or parts of a list.
del colors[4]
#The following statement removes blue for the list
colors.remove("blue")
colors.pop(3)
#This statement is used to print the colors
print(colors)
The output is: ['violet', 'indigo', 'green', 'red']
Refer the attached image for the output.
Attachments:

Similar questions