CBSE Class 12 Computer Science
Question 19 of 68
Data Structures - I : Linear Lists — Question 1
Back to all questions[10, 23, 56, [95, 10]]
Reason —
a = [10, 23, 56, [78, 10]]— This creates a nested lista.b = list(a)— This creates a shallow copy ofaand assigns it tob. The listbreferences to the same objects asa.a[3][0] += 17—a[3]accesses the sublist at index 3, i.e., [78, 10], and[0]further accesses the first element of that sublist, i.e., 78. Then, it adds 17 to 78, changing it to 95.print(b)— This prints the contents of listb. Sincebis a shallow copy ofa, any changes made to the nested list withinawill also reflect inb. Therefore, when we printb, we'll see the modified value [95, 10].