Python List append vs extend
Multiple Choice Medium
Question
After `a = [1, 2]; a.append([3, 4])`, what is `a`?
Hint
append adds one element; extend adds multiple elements.
Explanation
append() adds its argument as a single element. So [1, 2].append([3, 4]) adds the list [3, 4] as one item, giving [1, 2, [3, 4]]. Use extend() if you want [1, 2, 3, 4].
Related Resources
Related Lessons
- Lists
List methods.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.