Python List append()

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

The append() method adds a single item to the existing list. It doesn't return a new list; rather it modifies the original list.

The syntax of append() method is:

list.append(item)

append() Parameters

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

The item can be numbers, strings, another list, dictionary etc.


Return Value from append()

As mentioned, the append() method only modifies the original list. It doesn't return any value.


Example 1: Adding Element to a List

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

# an element is added
animal.append('guinea pig')

#Updated Animal List
print('Updated animal list: ', animal)

When you run the program, the output will be:

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

Example 2: Adding List to a List

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

# another list of wild animals
wild_animal = ['tiger', 'fox']

# adding wild_animal list to animal list
animal.append(wild_animal)

#Updated List
print('Updated animal list: ', animal)

When you run the program, the output will be:

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

It's important to notice that, a single item (wild_animal list) is added to the animal list in the above program.

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