Questenaتدريب يوضح لك ما ينبغي مراجعته لاحقًا
السؤال 33

A program runs `a = [1]`, `b = a`, and `b.append(2)`. What is `a`?

  1. `[1]`, because assignment deep-copies lists
  2. `[2]`, because append replaces the old contents
  3. `None`, because append returns no value
  4. `[1, 2]`, because both names refer to one listالإجابة الصحيحة

الشرح

Assignment copies the reference, not the list, so `a` and `b` designate the same mutable object. Appending through either name is therefore visible through the other; a separate `[1]` would require an explicit copy.

تابع هذا الاختبار

بدء التدريب
السؤال 33: A program runs `a = [1]`, `b = a`, and `b.append(2)`. What… · Python Fundamentals · Questena