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