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