Questenaتدريب يوضح لك ما ينبغي مراجعته لاحقًا
السؤال 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.الإجابة الصحيحة

الشرح

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.

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

بدء التدريب
السؤال 4: A program runs `a = b = list()` and then `a.append(7)`.… · Python Fundamentals · Questena