Python List append()

The append() method adds an item to the end of the list. Here's a quick example.

currencies = ['Dollar', 'Euro', 'Pound']

# Append 'Yen' to the list
currencies.append('Yen')

print(currencies)

# Output: ['Dollar', 'Euro', 'Pound', 'Yen']

append() Syntax

The syntax of append() is:

my_list.append(item)

Arguments

The method takes a single argument, which can be a number, string, list or any other object.

Return Value

The method doesn't return any value (it returns None).


Example: Don't Use Return Value

# Animals list
animals = ['cat', 'dog', 'rabbit']

# Add 'guinea pig' to the list
result = animals.append('guinea pig')

print('Updated animals list: ', result)

Output

None

The append() method updates the list itself and doesn't return any value. Therefore, there is no point in using the return value of append(), as it's always None.


Example: Adding Sequences to a List

# animals list
animals = ['cat', 'dog', 'rabbit']

# List of wild animals
wild_animals = ['tiger', 'fox']

# Appending wild_animals list to animals
animals.append(wild_animals)

print(animals)

Output

['cat', 'dog', 'rabbit', ['tiger', 'fox']]

In the program, a single item (wild_animals list) is added to the animals list. If you need to append the items of a sequence (rather than the sequence itself) to the list, use the extend() method.


Also Read:

Did you find this article helpful?