append()
Adds an element to the end of the list.
Syntax
items.append(element)
Description
Adds the given element to the end of the list. Modifies the list in-place, does not return new items.
Returns
None (it changes the list).
Example
Loading editor…
Expected output
['apple', 'pear']
When to use?
Filling items with a loop, lists that grow as the user adds elements.
Common mistakes
- ⚠️ basket = basket.append(x) WRONG — append returns None, you will delete the list.