Python
Lists
Programming
Python Tips
Append Functions

How to append multiple values to a list in Python

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Python, list.append(...) adds exactly one object to the end of a list. If you want to add several values, the right tool is usually extend(...) or list concatenation, depending on whether you want to modify the existing list or create a new one.

This distinction matters because “append multiple values” can mean two different things. Sometimes you want to add several separate elements. Sometimes you want to add one nested list as a single element. Python treats those cases differently.

append Adds One Object

The append method never spreads an iterable into multiple list elements. It appends the argument as one item.

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

Output:

python
[1, 2, [3, 4]]

That is correct behavior, but it surprises people who expected [1, 2, 3, 4].

Use extend for Multiple Elements

If you want to add each element from another iterable, use extend.

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

Output:

python
[1, 2, 3, 4]

extend iterates over the provided iterable and appends each element individually.

It works with lists, tuples, sets, generators, and strings, although strings need caution because they extend character by character.

You Can Also Use +=

The += operator is another concise way to extend a list.

python
numbers = [1, 2]
numbers += [3, 4]
print(numbers)

For lists, this mutates the existing list similarly to extend.

This is convenient, but extend is often clearer when you want to emphasize that elements are being added from another iterable.

Create a New List With Concatenation

If you do not want to modify the original list, use + to create a new one.

python
1original = [1, 2]
2combined = original + [3, 4]
3print(original)
4print(combined)

This leaves original unchanged and produces a fresh list.

That is useful when immutability-by-convention or functional-style code is important.

Add Multiple Values in a Loop

Sometimes the values are generated over time. In that case, a loop plus append is fine.

python
1numbers = []
2for value in range(3, 6):
3    numbers.append(value)
4print(numbers)

This is not wrong just because extend exists. Use the style that matches how the values are produced.

Be Careful With Strings

A common surprise is extending with a string.

python
letters = ['a']
letters.extend("bc")
print(letters)

Output:

python
['a', 'b', 'c']

If you meant to add the whole string as one element, use append("bc") instead.

Choosing the Right Method

Use this rule of thumb:

  • 'append(x) when x should become one new list element'
  • 'extend(xs) when each element of xs should be added individually'
  • '+ when you want a new list rather than mutating the old one'
  • a loop with append when values arrive one at a time

Once you think in terms of “one object” versus “many elements,” the choice becomes obvious.

Common Pitfalls

A common mistake is using append([3, 4]) when the desired result was to add two separate numbers. That creates a nested list.

Another mistake is using extend with a string and accidentally splitting it into individual characters.

Developers also sometimes use + inside a loop, which repeatedly creates new lists and can be less efficient than extending one list in place.

Finally, do not treat append and extend as interchangeable. They express different structure.

Summary

  • 'append adds one object to the list.'
  • 'extend adds each element from an iterable.'
  • '+= behaves like in-place extension for lists.'
  • '+ creates a new list instead of mutating the existing one.'
  • The key question is whether you want one new element or many new elements.

Course illustration
Course illustration

All Rights Reserved.