What is the recommended way to give a function parameter a fresh empty list as its default on every call?
Correct answer D. Use items=None and create the list inside the function when items is None
Explanation
Default values are evaluated only once, when the function is defined, so items=[] or even items=[].copy() is shared across calls. The idiom is to default to None and then write if items is None: items = []. This creates a new list on every call that omits the argument.
Answer checked How we write and check questions
Discussion