QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 75

The code runs def add(items): items.append(3), then items = [1, 2], then add(items). What is items afterward?

  1. [3]
  2. [1, 2]
  3. [1, 2, 3]Ճիշտ պատասխան
  4. [1, 2, 3, 3]

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

The parameter and the caller's name refer to the same list object, so append changes the list visible to the caller. Automatic deep copying would isolate the mutation, but Python calls do not make such copies.

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

Սկսել վարժանքը
Հարց 75: The code runs def add(items): items.append(3), then items =… · Python Fundamentals · Questena