QuestenaPractice that shows what to review next
Question 4

A program runs `a = b = list()` and then `a.append(7)`. What is the value of `b`?

  1. It is an empty list because `b` received a copy.
  2. It is `None` because append has no list result.
  3. Reading `b` raises NameError.
  4. It is `[7]` because both names share one list.Correct answer

Explanation

The chained assignment evaluates `list()` once and binds both names to that one list. Appending through `a` mutates the shared object, so expecting `b` to remain empty incorrectly assumes that the constructor ran separately for each target.

Continue with this test

Start practice
Question 4: A program runs `a = b = list()` and then `a.append(7)`.… · Python Fundamentals · Questena