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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github