Exam-style question
Try this first
Which Python expression prepends the item 7 to the list xs?.
- A.xs + [7]
- B.[7] + xs
- C.xs.append(7)
- 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.
