Carefully analyse the Python program given below and answer the following…

2026

Carefully analyse the Python program given below and answer the following questions that follow based on the program execution and output.

L1 = [1, 2, 3]        # Line 01
L2 = L1               # Line 02
L3 = L1.copy()        # Line 03
print(L2.pop(2))      # Line 04
L1.insert(1, 0)       # Line 05
L3.extend(L2)         # Line 06
L4 = L3.reverse()     # Line 07
print(L2)             # Line 08
print(L3)             # Line 09
print(L4)             # Line 10

(A) Write the output of the print statement in Line 04.

(B) Write the output of the print statement in Line 08.

(C) Write the output of the print statement in Line 09.

(D) Write the output of the print statement in Line 10.

Show answer & explanation

(A) Line 04 Output:
L2 and L1 refer to the same list [1, 2, 3].
pop(2) removes element at index 2 i.e., 3.
Output: 3

(B) Line 08 Output:
After pop, list becomes [1, 2].
L1.insert(1, 0) modifies it to [1, 0, 2]. Since L2 refers to same list:
Output: [1, 0, 2]

(C) Line 09 Output:
L3 was [1, 2, 3]. After extend(L2): [1, 2, 3, 1, 0, 2]
After reverse(): [2, 0, 1, 3, 2, 1]
Output: [2, 0, 1, 3, 2, 1]

(D) Line 10 Output:
reverse() returns None, so L4 = None
Output: None

Explore the full course: Hpsc Pgt Computer Science