List Methods
append()
Add a single item to the end of the list.
list.append(item)
list.append() adds the specified item to the end of the list, increasing the list's length by one.
The operation modifies the list in place and does not return a new list.
Arguments
Parameters
| Name | Description |
|---|---|
| item | The element to add (can be any object, including another list or dictionary). |
Result
Returns
None, the list is mutated in place.
Run it
Try it
Run it and change it
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits) Output
Press Run to see what it prints.Worth knowing
- Nested lists: Passing a list to
append()adds the entire list as a single nested element:[1].append([2, 3])becomes[1, [2, 3]]. To merge elements individually, useextend().