Question

Python List append() vs extend(): What’s the Difference?

pythonlistdata-structuresappendextend

Question

In Python, what is the difference between the list methods append() and extend()?

For example, how does each method affect a list when adding a single value versus adding multiple values from another iterable?

Short Answer

By the end of this page, you will understand how append() and extend() work in Python lists, when to use each one, and how they change the structure of a list differently. You will also see common mistakes, practical examples, and a small project to help reinforce the concept.

Concept

Python lists provide several methods for adding data, and two of the most commonly confused ones are append() and extend().

  • append(x) adds one item to the end of a list.
  • extend(iterable) adds each item from an iterable to the end of a list.

This difference matters because it changes the final shape of your list.

append()

When you use append(), Python takes the object you give it and places that object at the end of the list as a single element.

numbers = [1, 2, 3]
numbers.append([4, 5])
print(numbers)

Output:

[1, 2, 3, [4, 5]]

The list [4, 5] is added as one item inside the original list.

extend()

When you use extend(), Python loops over the iterable you provide and adds each element one by one.

numbers = [1, 2, 3]
numbers.extend([4, 5])
print(numbers)

Output:

[1, 2, 3, 4, 5]

Here, the elements 4 and 5 are added individually.

Why this matters

In real programs, this affects:

  • whether you create a nested list or a flat list
  • how later loops and indexing behave
  • whether your data structure matches what the rest of the program expects

If you use the wrong method, your code may still run but produce the wrong shape of data.

Mental Model

Think of a list like a shopping bag.

  • append() is like putting one object into the bag, even if that object is another smaller bag.
  • extend() is like opening a smaller bag and pouring all its contents into the main bag.

Example:

  • append(["apple", "banana"]) puts the whole fruit bag into your shopping bag.
  • extend(["apple", "banana"]) takes out each fruit and adds them separately.

So the key question is:

Do you want to add one item, or do you want to add all the items inside something iterable?

Take Quiz

Syntax and Examples

Core syntax

my_list.append(item)
my_list.extend(iterable)

Example 1: Add a single value with append()

fruits = ["apple", "banana"]
fruits.append("orange")
print(fruits)

Output:

['apple', 'banana', 'orange']

This is the normal use of append(): adding one new element.

Example 2: Add multiple values with extend()

fruits = ["apple", "banana"]
fruits.extend(["orange", "grape"])
print(fruits)

Output:

['apple', 'banana', 'orange', 'grape']

This adds each new fruit separately.

Example 3: append() with a list

fruits = ["apple", "banana"]
fruits.append(["orange", "grape"])
print(fruits)

Output:

['apple', 'banana', ['orange', 'grape']]

This creates a nested list.

Example 4: extend() with a string

letters = ["a", "b"]
letters.extend("cd")
print(letters)

Output:

['a', 'b', 'c', 'd']

A string is iterable, so extend() adds each character one by one.

Example 5: append() with a string

letters = ["a", "b"]
letters.append("cd")
print(letters)

Output:

['a', 'b', 'cd']

The whole string is added as one element.

Step by Step Execution

Consider this example:

items = [1, 2]
items.append([3, 4])
print(items)

items = [1, 2]
items.extend([3, 4])
print(items)

First part: append()

items = [1, 2]
  • A list is created with two elements: 1 and 2.
items.append([3, 4])
  • Python takes the object [3, 4].
  • It adds that object as one new element at the end.
  • The list becomes:
[1, 2, [3, 4]]
print(items)
  • Output:
[1, 2, [3, 4]]

Second part: extend()

items = [1, 2]
  • The list is reset to [1, 2].
items.extend([3, 4])
  • Python loops through [3, 4].
  • It adds 3 to the list.
  • Then it adds 4 to the list.
  • The final list becomes:
[1, 2, 3, 4]
print(items)
  • Output:
[1, 2, 3, 4]

Key result

  • append([3, 4]) → one new element
  • extend([3, 4]) → two new elements

Real World Use Cases

Building a list of results

If you are collecting one result at a time, append() is usually the right choice.

errors = []
errors.append("Missing email")
errors.append("Password too short")

Merging multiple records

If you already have a list of items and want to add them all to another list, extend() is better.

all_users = ["Ana", "Ben"]
new_users = ["Cara", "Dan"]
all_users.extend(new_users)

Preserving grouped data

Sometimes you intentionally want a nested list. In that case, use append().

rows = []
rows.append([1, 2, 3])
rows.append([4, 5, 6])

This is useful for table-like data where each row should stay grouped.

Combining API or file data

If an API returns a list of records, you often use extend() to combine them into one larger list.

page1 = ["item1", "item2"]
page2 = ["item3", "item4"]
page1.extend(page2)

Token or character processing

Because strings are iterable, extend() can be useful when adding characters individually.

chars = []
chars.extend("cat")
Take Quiz

Real Codebase Usage

In real projects, developers choose between append() and extend() based on the intended data shape.

Common patterns

Add one processed item at a time

cleaned = []
for name in raw_names:
    cleaned.append(name.strip())

Use append() when each loop iteration produces one final item.

Merge a batch of items

all_logs = []
for batch in log_batches:
    all_logs.extend(batch)

Use extend() when each loop iteration produces a list or iterable of many items.

Guard against wrong input shape

def add_tags(existing_tags, new_tags):
    if not isinstance(new_tags, list):
        raise TypeError("new_tags must be a list")
    existing_tags.extend(new_tags)

This avoids accidentally extending with a string or another unexpected iterable.

Building nested structures intentionally

matrix = []
matrix.append([1, 2])
matrix.append([3, 4])

Here, append() is correct because each inner list is meant to remain separate.

Style note

Both methods modify the original list in place and return None. That means they are usually used as standalone statements, not inside expressions.

Common Mistakes

1. Using append() when you meant extend()

Broken example:

nums = [1, 2]
nums.append([3, 4])
print(nums)

Output:

[1, 2, [3, 4]]

If you wanted a flat list, use:

nums = [1, 2]
nums.extend([3, 4])

2. Using extend() with a string by accident

Broken example:

words = ["hello"]
words.extend("world")
print(words)

Output:

['hello', 'w', 'o', 'r', 'l', 'd']

If you wanted to add the whole string as one item, use:

words.append("world")

3. Expecting a return value

Broken example:

nums = [1, 2]
result = nums.append(3)
print(result)

Output:

None

Correct understanding:

  • append() changes the list in place
  • extend() also changes the list in place
  • neither returns the updated list

4. Chaining list methods

Broken example:

nums = [1, 2]
nums.append(3).append(4)

This fails because nums.append(3) returns None.

5. Forgetting that extend() needs an iterable

Broken example:

nums = [1, 2]
nums.extend(3)

This raises an error because 3 is not iterable.

Use either:

nums.append(3)

or:

nums.extend([3])

Comparisons

Featureappend()extend()
AddsOne itemMultiple items from an iterable
Argument typeAny objectAn iterable
If given a listAdds the whole list as one elementAdds each element of the list
If given a stringAdds the whole string as one elementAdds each character
Resulting structureCan create nested listsUsually keeps list flat
Modifies list in placeYesYes
Return valueNoneNone

append() vs +

a = [1, 2]
a.append(3)

versus

a = [1, 2]
a = a + [3]

Differences:

  • append() changes the existing list
  • + creates a new list
  • append() adds one item
  • + combines two lists

extend() vs +=

a = [1, 2]
a.extend([3, 4])

is similar to:

a = [1, 2]
a += [3, 4]

In common list usage, both add multiple items to the existing list.

Take Quiz

Cheat Sheet

# Add one item
my_list.append(item)

# Add all items from an iterable
my_list.extend(iterable)

Quick rules

  • Use append() for one item.
  • Use extend() for many items from an iterable.
  • append([1, 2]) → adds one nested list
  • extend([1, 2]) → adds 1 and 2
  • append("ab") → adds one string
  • extend("ab") → adds 'a' and 'b'
  • Both modify the list in place.
  • Both return None.

Mini examples

x = [1, 2]
x.append(3)       # [1, 2, 3]

x = [1, 2]
x.append([3, 4])  # [1, 2, [3, 4]]

x = [1, 2]
x.extend([3, 4])  # [1, 2, 3, 4]

Common edge cases

x.extend("hi")    # adds 'h', 'i'
x.append("hi")    # adds "hi"
x.extend([5])      # adds 5
x.append([5])      # adds [5]

FAQ

Does append() add multiple items in Python?

No. append() always adds exactly one object to the end of the list. That object can itself be a list.

Does extend() create a nested list?

Usually no. extend() takes items from an iterable and adds them one by one, which usually keeps the list flat.

Can I use extend() with a string?

Yes, because a string is iterable. But it will add each character separately, which is often not what beginners expect.

Do append() and extend() return a new list?

No. Both methods modify the original list in place and return None.

When should I use append() instead of extend()?

Use append() when you want to add a single item, including when that single item is another list.

When should I use extend() instead of append()?

Use extend() when you already have multiple items in an iterable and want to add all of them to the list.

Is a += b the same as a.extend(b)?

For lists in common usage, they behave similarly when b is an iterable of items to add.

Take Quiz

Mini Project

Description

Create a simple Python program that builds a playlist. This project demonstrates when to use append() for adding one song and when to use extend() for adding a batch of songs from another list.

Goal

Build a playlist correctly using both append() and extend() so you can see the difference in the final list structure.

Requirements

  1. Start with a list containing at least two song titles.
  2. Add one new song using append().
  3. Add multiple songs from another list using extend().
  4. Print the playlist after each change.
  5. Also show what happens if you use append() with a list of songs instead of extend().
Take Quiz

Keep learning

Related questions

View more