logo

Question detail

Which Python expression prepends the item 7 to the list xs?

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

MCQ

Type

practice

Style

Topic

Lists in functional programming

Exam-style question

Try this first

Which Python expression prepends the item 7 to the list xs?.

  1. A.xs + [7]
  2. B.[7] + xs
  3. C.xs.append(7)
  4. D.xs[7]

Model answer

What a good answer should say

  • [7] + xs

Explanation

Why this works

Adding [7] before xs creates a new list with 7 as its first element. xs + [7] would append 7 instead.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.