GIAC
GPYC · Question #44
What is the output of the following when executed in a Python shell? >>> listoflists = [[1,2],[3,4]] >>> copyoflists = list(listoflists) >>> copyoflists.append([5,6]) >>> copyoflists [[1, 2], [3, 4],
Sign in or unlock GPYC to reveal the answer and full explanation for question #44. The question stem and answer options stay visible for context.
Python Fundamentals & Command Line Tools
Question
What is the output of the following when executed in a Python shell?
listoflists = [[1,2],[3,4]] copyoflists = list(listoflists) copyoflists.append([5,6]) copyoflists [[1, 2], [3, 4], [5, 6]] copyoflists[0].append(2.5) copyoflists [[1, 2, 2.5], [3, 4], [5, 6]] listoflists
Options
- A[[1, 2, 2.5], [3, 4], [5, 6]]
- B[[1,2], [3,4], [5,6]]
- C[[1,2], [3,4]]
- D[[1,2,2.5], [3,4]]
Unlock GPYC to see the answer
You've previewed enough free GPYC questions. Unlock GPYC for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.
Topics
#shallow copy#list of lists#mutable objects#memory model