Add Item to a List in Python: Mastering Append, Insert, and More
Being able to add items to a list is a routine task for Python developers. Learn multiple ways to do that so you can write programs faster.
Python provides multiple ways to add an item to a list. Traditional ways are the append(), extend(), and insert() methods. The best method to choose depends on two factors: the number of items to add (one or many) and where you want to add them in the list (at the end or at a specific location / index).
By the end of this article, adding items to a Python list will be one of your skills.
Let’s dive in!
Add One Item to a List in Python Using the append() Method
Once you start writing Python code you will quickly realize that lists are one of the most commonly used data structures in Python.
The most basic way to add an item to a list in Python is by using the list append() method. A method is a function that you can call on a given Python object (e.g. a list) using the dot notation.
Create a list of strings that contains the names of three cities. You will use the append() method to add a fourth string to the list:
cities = ["London", "New York", "Rome"]
You can see that to call the append() method we have specified the name of the list (cities) followed by a dot and then followed by the append method.
We have passed the item to be added to the list to the append method.
Here is what the list looks like after appending the new item to it:
['London', 'New York', 'Rome', 'Paris']
Notice that the last item we have added to the list appears at the end of the list. That’s because Python lists are ordered data structures.
In other words…
The list append() method adds a single item to the end of a list in Python.
Can You Add Multiple Items to a Python List Using the append() Method?
How can you add several items to a Python list using the append() method?