QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 28

What does `items.insert(1, "x")` do when `items` is `["a", "b"]`?

  1. It changes the list to `["a", "x", "b"]`.Ճիշտ պատասխան
  2. It changes the list to `["a", "b", "x"]`.
  3. It replaces `"b"` and leaves two elements.
  4. It raises IndexError because index 1 is occupied.

Բացատրություն

Insertion at index 1 places the new value before the element that was at that index, producing `a`, `x`, `b` in order. It does not replace `b`, because slice or indexed assignment would be needed for replacement.

Շարունակեք այս թեստով

Սկսել վարժանքը
Հարց 28: What does `items.insert(1, "x")` do when `items` is `["a",… · Python Fundamentals · Questena