What is the difference between Python's list methods append and extend?

Better Stack Team
Updated on January 26, 2023

The append() method adds an item to the end of the list. The item can be of any type, and you can use the method to add multiple items by separating them with a comma. For example:

 
fruits = ['apple', 'banana', 'mango']
fruits.append('orange')
print(fruits)
# Output: ['apple', 'banana', 'mango', 'orange']

fruits.append('grapes', 'strawberry')
print(fruits)
# Output: ['apple', 'banana', 'mango', 'orange', 'grapes', 'strawberry']

On the other hand, the extend() method takes an iterable (such as a list) and adds each element of the iterable to the list one by one. For example:

 
fruits = ['apple', 'banana', 'mango']
new_fruits = ['orange', 'grapes', 'strawberry']
fruits.extend(new_fruits)
print(fruits)
# Output: ['apple', 'banana', 'mango', 'orange', 'grapes', 'strawberry']

In summary, the main difference between append() and extend() is that append() adds a single item to the list, while extend() adds multiple items to the list.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →