English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The append() method adds an item to the end of the list.
The append() method adds a single item to the end of the list.
The syntax of the append() method is:
list.append(item)
This method has one parameter
item -Item to be added to the end of the list
The item can be a number, string, dictionary, another list, etc.
This method does not return any value (returns None).
# Animal list animals = ['cat', 'dog', 'rabbit'] # Add monkey to the animal list animals.append('monkey') # The animal list after appending print('New animal list: ', animals)
Output result
New animal list: ['cat', 'dog', 'rabbit', 'monkey']
# Animal list animals = ['cat', 'dog', 'rabbit'] # List of wild animals wild_animals = ['tiger', 'fox'] # Add the wild animal list to the animal list animals.append(wild_animals) print('New animal list: ', animals)
Output result
New animal list: ['cat', 'dog', 'rabbit', ['tiger', 'fox']]
It is important to note that in the above program, the items (wild_animals list) have been added to the animals list.
If you need to add items from a list to another list (not the list itself), you need to useextend() method.