QuestenaPractice that shows what to review next
Question 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 listCorrect answer

Explanation

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.

Continue with this test

Start practice
Question 33: A program runs `a = [1]`, `b = a`, and `b.append(2)`. What… · Python Fundamentals · Questena