Python List append()

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

Example

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

# append 'Yen' to the list currencies.append('Yen')
print(currencies)
# Output: ['Dollar', 'Euro', 'Pound', 'Yen']

Syntax of List append()

The syntax of the append() method is:

list.append(item)

append() Parameters

The method takes a single argument

  • item - an item (number, string, list etc.) to be added at the end of the list

Return Value from append()

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


Example 1: Adding Element to a List

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

# Add 'guinea pig' to the list animals.append('guinea pig')
print('Updated animals list: ', animals)

Output

Updated animals list:  ['cat', 'dog', 'rabbit', 'guinea pig']

Example 2: Adding List 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('Updated animals list: ', animals)

Output

Updated animals list:  ['cat', 'dog', 'rabbit', ['tiger', 'fox']]

In the program, a single item (wild_animals list) is added to the animals list.

Note: If you need to add items of a list (rather than the list itself) to another list, use the extend() method.


Also Read:

Before we wrap up, let’s put your knowledge of Python list append() to the test! Can you solve the following challenge?

Challenge:

Write a function to add an item to the end of the list.

  • For example, for inputs ['apple', 'banana', 'cherry'] and 'orange', the output should be ['apple', 'banana', 'cherry', 'orange'].
Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community