QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 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]Ճիշտ պատասխան
  4. [1, 1]

Բացատրություն

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.

Շարունակեք այս թեստով

Սկսել վարժանքը
Հարց 110: Given def add(items=[]): items.append(len(items)); return… · Python Fundamentals · Questena