QuestenaPractice that shows what to review next
Question 109

A function definition uses a list as a parameter default. When is that list created, and what happens when later calls omit the argument?

  1. It is created at def time and reused.Correct answer
  2. A new copy is made before every call.
  3. It is created only after the first return.
  4. A new object is created for each omission.

Explanation

The list is created as the def statement executes, and omitted arguments bind to that same object on later calls. Assuming a fresh list or an automatic copy for every call hides the sharing that makes mutable defaults risky.

Continue with this test

Start practice
Question 109: A function definition uses a list as a parameter default.… · Python Fundamentals · Questena