nerdexam
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…

The correct answer is D. [[1,2,2.5], [3,4]]. You've hit your limit · resets 1pm (America/New_York)

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]]

How the community answered

(27 responses)
  • A
    22% (6)
  • B
    4% (1)
  • C
    11% (3)
  • D
    63% (17)

Explanation

You've hit your limit · resets 1pm (America/New_York)

Topics

#shallow copy#list of lists#mutable objects#memory model

Community Discussion

No community discussion yet for this question.

Full GPYC Practice