Python List append() - Append Items to List

The append() method adds a new item at the end of the list.

Syntax:

list.append(item)

Parameters:

item: An element (string, number, object etc.) to be added to the list.

Return Value:

Returns None.

The following adds an element to the end of the list.

Example: append()
city = 'Delhi'
cities = ['Mumbai', 'London', 'Paris', 'New York']
cities.append(city)
print(cities)
Output
['Mumbai', 'London', 'Paris', 'New York', 'Delhi']

The following adds a list to the end of the list.

Example: Append List
otherCities = ['Delhi','Chennai']
cities = ['Mumbai', 'London', 'Paris', 'New York']
cities.append(otherCities)
print(cities)
Output

['Mumbai', 'London', 'Paris', 'New York', ['Delhi', 'Chennai']]

In the above example, the otherCities list is added to the list cities as a single item.

Any type of variable can be added to the list.

Example: Append Numbers to List
number = 1
cities = ['Mumbai', 'London', 'Paris', 'New York']
cities.append(number)
print(cities)
Output
['Mumbai', 'London', 'Paris', 'New York', 1]