1 1 vote What is the output of the following Python code?list1 = [1, 2, [3, 4]] list2 = list(list1) list1[2][0] = 99 list1[0] = 100 print(list2)$[1,2,[99,4]]$ $[100,2,[3,4]]$ $[1,2,[3,4]]$ $[100,2,[99,4]]$ Programming in Python goclasses python-&-dsa goclasses-da-dpp goclasses-da-dpp-day-86 goclasses-python-&-dsa-practice-questions + – GO Classes 218 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes $\verb|list2 = list(list1)|$ A new list, $\verb|list2|$ , is created.The first two elements (integers 1 and 2 ) are copied by value (since integers are immutable). The third element is a reference to the same nested list $\verb|[3, 4]|$ that $\verb|list1|$ points to. $\verb|list1[2][0] = 99|$ This modifies the first element of the nested list. Because both $\verb|list1[2]|$ and $\verb|list2[2]|$ point to the same object in memory, this change is reflected in both lists. At this point, $\verb|list2|$ looks like $\verb|[1, 2, [99, 4]]|$. GO Classes answered Jan 13 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.