Tutorial Study Image

Python append()

The append() function in python helps to add the given item to the end of the existing list.


list.append(item) #where item can be numbers, strings, dictionaries etc
 

append() Parameters:

The append() function takes a single parameter.

Parameter Description Required / Optional
item an item to be added at the end of the list Required

append() Return Value

This method doesn't return any value which means it returns none. Actually, this method updates the existing list.

Examples of append() method in Python

Example 1: How append() works in python?


# flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']

# 'Sunflower' is appended to the flowers list
flowers.append('Sunflower')

# Updated flowers list
print('Updated flowers list: ', flowers )
 

Output:


Updated flowers list:  ['Rose', 'Lotus', 'Jasmine', 'Sunflower']

Example 2: How to add list to a list using append()


# flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']


# flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']

# list of vegetables 
vegetables = ['Tomato', 'Potato']

# appending vegetables list to the flowers list
flowers.append(vegetables)

print('Updated list: ', flowers)
 

Output:



Updated list:  ['Rose', 'Lotus', 'Jasmine', ['Tomato', 'Potato']]