Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output :
L1= [x ** 2 for x in range(10) if x % 3 == 0]
L2 = L1
L1.append(len(L1))
print(L1)
print(L2)
L2.remove(len(L2) - 1)
print(L1)
Python
Linear Lists
1 Like
Answer
[0, 9, 36, 81, 4]
[0, 9, 36, 81, 4]
[0, 9, 36, 81]
Working
L1 = [x ** 2 for x in range(10) if x % 3 == 0]
— This line creates a listL1
containing the squares of multiples of 3 between 0 to 9.L2 = L1
— This line assigns listL1
to listL2
, meaning bothL1
andL2
reference the same list in memory (shallow copy).L1.append(len(L1))
— This line appends the length ofL1
toL1
. So, the length ofL1
is 4, and it appends 4 toL1
.print(L1)
— This prints the modifiedL1
list.print(L2)
— This printsL2
, which is pointing to the same list asL1
.L2.remove(len(L2) - 1)
— This line removes the last element ofL2
sincelen(L2) - 1
gives the last index ofL2
.print(L1)
— This printsL1
again. Since bothL1
andL2
reference the same list, modifyingL2
also affectsL1
. Therefore,L1
also reflects the change made toL2
.
Answered By
3 Likes