Difference between append() and extend() in Python

When I started working with Python lists, I often confused the append() and extend() methods. Both looked like they were adding elements to a list, but the results were not always what I expected.

Over the years, I realized that many beginners face the same confusion. So, in this tutorial, I will walk you through the difference between append() and extend() in Python.

I’ll explain each method with simple examples, show you how they behave differently, and share some real-world use cases where one works better than the other.

Extend vs Append in Python

Let me summarize the differences in a simple table:

Basis of Comparisonappend()extend()
Syntaxlist_name.append (element)list_name.extend (iterable)
InputThis accepts only one input element.extend() method has time complexity of 0(K). Where k is the length of the list that needs to be added.
FunctionalityThe append() method in Python adds a single element to the end of the existing list.While the extend() method in Python appends several items to a list as individual items at the end of the list.
OperationThe append () method adds the full input to the list as a single item.The extent() method adds each item to the list separately after iterating through each one in the input.
EfficiencyIt is typically quicker and more effective than extend() since append() only executes one operation at a time.When adding elements from different iterables or with large inputs, extend() can take a longer time.
Time Complexityappend() method has constant time complexity, 0(1).extend() method has time complexity of 0(K). Where k is the length of the list which needs to be added.
This is the list of statements for extend vs append in Python. Now, let’s go to the actual methods one by one and understand them in deep:

What is the append() method in Python?

The append() method is a predefined method in a list in Python, used to add a single element to the end of the existing list. It can be called using the dot notation.

Let me make it clear by showing examples using the append() method in Python.

existing_values = [4,7.8,6.3,9,3]
existing_values.append(3.5)
print(existing_values)

Output:

[4, 7.8, 6.3, 9, 3, 3.5]

I executed the above example code and added the screenshot below.

.extend vs .append in Python

Now, I will show you how to append multiple values to an existing list using the append() method in Python lists.

existing_values = [4,7.8,6.3,9,3]
new_values = [2.8,11,3.8]
for num in new_values:
    existing_values.append(num)
print(existing_values)

Output:

[4, 7.8, 6.3, 9, 3, 2.8, 11, 3.8]

I executed the above example code and added the screenshot below.

append and extend in python

To store the value that we want to add in a separate list, we can use a for loop to call the append() method in a list in Python as many times as needed.

What is the extend() method in Python?

The extend() method is a built-in method in Python lists used to add each item to the list separately after iterating through each one in the input. It will be called using dot notation. To make you understand, I will show you an example using the extend() method in Python.

existing_list = [7,8.4,6.3,9,3]
new_list = [2.8,1,3.7]
existing_list.extend(new_list)
print(existing_list)

Output:

[7, 8.4, 6.3, 9, 3, 2.8, 1, 3.7]

I executed the above example code and added the screenshot below.

python extend vs append

The extend() method in Python adds all elements of another iterable to the end of a list, updating it in place.

Which is faster extend or the append method in Python?

We will find out which method is faster extend or append, by using the timeit function from the timeit module in Python. By using the timeit module, we can find out the run time of the program.

Timeit is the built-in Python library. This module provides a simple way to find the execution time of a Python program.

For Example, I have executed a Python program using the append and extend methods with a single value.

import timeit

def single_append(x, y):
    x.append(y)
temperature = [23, 21, 20, 25]

print(timeit.timeit('single_append(temperature, 32)', setup='from __main__ import single_append,temperature'))


def single_extend(x, y):
    x.extend(y)

temp = [23, 21, 20, 25]
more_temp = [34]
print(timeit.timeit('single_extend(temp, more_temp)', setup='from __main__ import single_extend,temp,more_temp'))

Output:

0.08402279997244477                     // Run time of single append value
0.10593359998892993                     // Run time of single extend value

Now, I will check which is faster to append multiple values or extending multiple values in a Python list.

Here is the full code to append multiple values and to extend multiple values in Python.

import timeit

def multiple_append(x, y):
    for i in y:
        x.append(i)

temp = [23, 21, 20, 25]
more_temp = [23, 33, 43]
print(timeit.timeit('multiple_append(temp, more_temp)', setup='from __main__ import multiple_append,temp,more_temp'))


def multiple_extend(x, y):
    x.extend(y)

temp = [23, 21, 20, 25]
more_temp = [23, 33, 43]
print(timeit.timeit('multiple_extend(temp, more_temp)', setup='from __main__ import multiple_extend,temp,more_temp'))

Output:

0.14341480005532503                      // Run time of append multiple value
0.09257480001542717                      // Run time of extend multiple value

When I was new to Python, I often used append() everywhere. But as I worked on larger projects, I realized that extend() is more powerful when dealing with multiple items at once.

Here’s how I decide today:

  • If I need to add one item, I use append().
  • If I need to add many items, I use extend().

Both methods are essential, and once you understand their differences, you’ll write cleaner and more efficient Python code.

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.