Python List append() Method

Appends an item to a list

Usage

The append() method adds a single item to the end of the list.

The method does not return anything; it modifies the list in place.

Syntax

list.append(item)

Python list append() method parameters
ParameterConditionDescription
itemRequiredAn item you want to append to the list

Examples

Example: Append item ‘yellow’ to the end of the list

L = ['red', 'green', 'blue']
L.append('yellow')
print(L)    # ['red', 'green', 'blue', 'yellow']

Example: Append list to a list

L = ['red', 'green', 'blue']
L.append([1,2,3])
print(L)    # ['red', 'green', 'blue', [1, 2, 3]]

Example: Append tuple to a list

L = ['red', 'green', 'blue']
L.append((1,2,3))
print(L)    # ['red', 'green', 'blue', (1, 2, 3)]

append() vs extend()

append() method treats its argument as a single object.

Example:

L = ['red', 'green']
L.append('blue')
print(L)    # ['red', 'green', 'blue']

Use extend() method, if you want to add every item of an iterable to a list.

Example:

L = ['red', 'green']
L.extend('blue')
print(L)    # ['red', 'green', 'b', 'l', 'u', 'e']