Python 3 reference · List Methods

Python List append() Method

Add one item to the end of a list, changing the list in place. Returns None.

Python 3 Since 3.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

list.append(item)

Parameters

ParameterDescription
item The value to add (it is added as one item, even if it is a list).

Return value

None.

Examples

Add to the endTry it yourself
fruits = ["apple"]
fruits.append("banana")
print(fruits)

Output

['apple', 'banana']
Build a list in a loopTry it yourself
squares = []
for n in range(5):
    squares.append(n * n)
print(squares)

Output

[0, 1, 4, 9, 16]
append() vs extend()Try it yourself
a = [1, 2]
a.append([3, 4])   # one nested item
print(a)
b = [1, 2]
b.extend([3, 4])   # several items
print(b)

Output

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

Common mistakes

  • append() returns None: items = items.append(x) throws your list away.
  • Appending a list adds it as one nested item; use extend() to add its items.

Version history

VersionChange
Python 3.0Added

In other languages

Was this page helpful?