CBSE Class 12 Computer Science
Question 21 of 68
Data Structures - I : Linear Lists — Question 3
Back to all questions[3, 7, 8, 6, 1, 2]
Reason —
lst = [3, 4, 6, 1, 2]— This line initializes a list variablelstwith the values [3, 4, 6, 1, 2].lst[1:2] = [7,8]—lst[1:2]refers to a slice of listlstat index 1. It replaces this slice with the values from the list[7, 8]. Nowlstbecomes[3, 7, 8, 6, 1, 2].
(If we change this line tolst[1] = [7, 8], then output would be[3, [7, 8], 6, 1, 2]because it would replace the entire element at index 1 (i.e., 4) with[7, 8].)print(lst)— This line prints the modified listlst.