PythonArraysBeginner

list.append()

Adds one item to the end of a list (mutates the list).

Review the syntaxStudy the examplesOpen the coding app
my_list.append(item)

This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.

What it does

Overview

Adds one item to the end of a list (mutates the list).

The append() method is used to add a single object to the end of a list. It is a fundamental operation that modifies the list object in-place and returns None to the caller. Performance-wise, appending is highly efficient with an amortized time complexity of O(1). This is because Python lists are implemented as dynamic arrays that over-allocate memory; reallocations (O(n)) occur only when the pre-allocated capacity is reached. A common behavior to note is that append() does not create a new list; it directly alters the internal buffer of the existing list. When an iterable such as a list, tuple, or dictionary is passed to append(), the entire collection is added as one single element, resulting in a nested structure rather than a flat extension of the original list.

Quick reference

Syntax

my_list.append(item)

Inputs

Parameters

itemAny · Item to add to the list.

See it in practice

Examples

1

Basic Appending

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

Adds a string element to the end of the list.

2

Appending a List (Nesting)

data = [1, 2, 3]
data.append([4, 5])
print(data)
Output:
[1, 2, 3, [4, 5]]

Demonstrates that appending a list results in a nested list structure, not a flattened one.

3

Using append in a Loop

squares = []
for i in range(5):
    squares.append(i * i)
print(squares)
Output:
[0, 1, 4, 9, 16]

A common pattern for dynamically building a list from an iterative process.

Debug faster

Common Errors

1

LogicError

Cause: Attempting to assign the result of append() to a variable, which results in None because the method operates in-place.

Fix: Call append() as a standalone statement and continue using the original list variable.

my_list = [1, 2]
new_list = my_list.append(3) # new_list is None
2

TypeError

Cause: Passing multiple arguments to the append() method. It accepts exactly one argument.

Fix: Use extend() to add multiple elements or wrap the elements in a single container like a tuple.

items = [1, 2]
items.append(3, 4) # Throws TypeError
3

LogicError

Cause: Confusing append() with extend() when the goal is to merge two lists.

Fix: Use extend() if you want to flatten the elements into the list, or the '+' operator for concatenation.

a = [1]
a.append([2, 3]) # Result is [1, [2, 3]], not [1, 2, 3]

Runtime support

Compatibility

Python 3.8+

Source: MDN Web Docs

Common questions

Frequently Asked Questions

Adds one item to the end of a list (mutates the list).

item: Item to add to the list.

LogicError: Call append() as a standalone statement and continue using the original list variable. TypeError: Use extend() to add multiple elements or wrap the elements in a single container like a tuple. LogicError: Use extend() if you want to flatten the elements into the list, or the '+' operator for concatenation.