What is the output of the following Python code snippet?
a = [1, 2, 3, 4]
a[1:3] = [5, 5]
print(a)
a[1:3] = [5, 5]
print(a)
Correct answer
B. [1, 5, 5, 4]
5 views
B. [1, 5, 5, 4]
5 views
Slice assignment can replace a slice with any number of items.
Asked in: Python Interview Lists
https://docs.python.org/3/tutorial/datastructures.htmlNot sure why the answer is B? Ask here and get an explanation.