QuestenaPractice that shows what to review next
Question 110

Given def add(items=[]): items.append(len(items)); return items, what does the second call to add() return after one earlier call to add()?

  1. [1]
  2. [0]
  3. [0, 1]Correct answer
  4. [1, 1]

Explanation

The first call appends 0, and the second call sees that retained element before appending 1, producing [0, 1]. A reset to [1] would require a fresh list, but both omitted calls mutate the same default container.

Continue with this test

Start practice
Question 110: Given def add(items=[]): items.append(len(items)); return… · Python Fundamentals · Questena