Appending Items to a Python List
Author: Newtum
This guide explains how to add items to the end of a list in Python using the `append()` and `extend()` methods.
Using `list.append()` to Add a Single Item
The `.append()` method adds a single element to the end of the list. The list is modified in-place.
Using `list.extend()` to Add Multiple Items
The `.extend()` method iterates over an iterable (like another list) and adds each of its elements to the end of the list. This is different from `append()`, which would add the iterable as a single nested element.
Using the `+` Operator
You can also use the `+` operator to concatenate two lists, which creates a new list. This is less memory-efficient than `extend()` if you don't need to preserve the original list.