निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
A=[[1,2,3],
[4,5,6],
[7,8,9]]
print(A[1][:]) A
[1, 2, 3]
B
[4, 5, 6]
C
[2, 5, 8]
D
None of these
Explanation
The correct answer is:
(B) [4, 5, 6]
Explanation:
Ais a 2D list (a list of lists), whereA[1]refers to the second list (since indexing starts from 0), which is[4, 5, 6].- The
[:]slice operator is used to copy the entire list at index1. So,A[1][:]gives the list[4, 5, 6].
Output:
(B) [4, 5, 6]
Correct Answer: B) [4, 5, 6]