What is the output of print([10, 20, 30, 40][1:3]) in Python?
print([10, 20, 30, 40][1:3])
Correct answer
D. [20, 30]
D. [20, 30]
Slice [1:3] returns elements at index 1 and 2.
Asked in: Python Interview Lists
https://docs.python.org/3/tutorial/datastructures.htmlNot sure why the answer is D? Ask here and get an explanation.