Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output.
b = [[9, 6], [4, 5], [7, 7]]
x = b[:2]
x[1].append(10)
print(x)
Python
Linear Lists
1 Like
Answer
[[9, 6], [4, 5, 10]]
Working
b = [[9, 6], [4, 5], [7, 7]]
— This line initializes a listb
containing three sublists, each containing two elements.x = b[:2]
— This line creates a new listx
by slicing the listb
from index 0 to index 1. So,x
will contain the first two sublists ofb
. At this point,x
will be[[9, 6], [4, 5]]
.x[1].append(10)
— This line accesses the second sublist ofx
, which is[4, 5]
, and appends 10 at its end. Nowx
becomes[[9, 6], [4, 5, 10]]
print(x)
— This line prints the listx
.
Answered By
3 Likes