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