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