निम्नलिखित कोड का आउटपुट क्या है?
What is the output of following code ?
A=[[1,2,3],
[4,5,6],
[7,8,9]]
print(A[1][:])
A)
B)
C)
D)
Explanation:
The correct answer is:
(B) [4, 5, 6]
Explanation:
A
is 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]