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

After `items = [3, 1, 2]` and `result = items.sort()`, what are `items` and `result`?

  1. `items` stays `[3, 1, 2]`; `result` is `[1, 2, 3]`.
  2. `items` is `[1, 2, 3]`; `result` is `None`.الإجابة الصحيحة
  3. Both names refer to the same sorted list.
  4. `items` is `None`; `result` is `[1, 2, 3]`.

الشرح

The method rearranges the existing list into sorted order and follows the in-place-method convention of returning `None`. Expecting `result` to hold a sorted list confuses `list.sort` with the separate `sorted` function.

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

بدء التدريب
السؤال 31: After `items = [3, 1, 2]` and `result = items.sort()`, what… · Python Fundamentals · Questena