2 2 votes Consider the following Python code:matrix = [[1, 2], [3, 4]] copy_matrix = matrix[:] copy_matrix[0][1] = 99 copy_matrix[1] = [7, 8] print(matrix, copy_matrix)What is the output of the code above?[[1, 2], [3, 4]] [[1, 99], [7, 8]][[1, 99], [7, 8]] [[1, 99], [7, 8]][[1, 99], [3, 4]] [[1, 99], [7, 8]][[1, 2], [7, 8]] [[1, 99], [7, 8]] Programming in Python goclasses goclasses-da-dpp goclasses-da-dpp-day-203 programming-in-python goclasses-python-&-dsa-practice-questions output + – GO Classes 91 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes The statement $\texttt{copy\_matrix = matrix[:]}$ creates a shallow copy of the outer list.This means $\texttt{matrix}$ and $\texttt{copy\_matrix}$ are different outer lists, but the inner lists are still shared.So $\texttt{copy\_matrix[0][1] = 99}$ changes the first inner list, which is shared by both outer lists.matrix = [[1, 99], [3, 4]]Then $\texttt{copy\_matrix[1] = [7, 8]}$ replaces only the second element of $\texttt{copy\_matrix}$ with a new list.It does not change $\texttt{matrix[1]}$.Therefore, the output is:[[1, 99], [3, 4]] [[1, 99], [7, 8]]Correct Option: C GO Classes answered Jun 18 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.