English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Fonctions en Python

Types de données en Python

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Knowledge of Python

Python Reference Manual

Python list append() usage and example

List methods in Python

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)

append() parameter

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.

append() return value

This method does not return any value (returns None).

Example1: Add element to list

# 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']

Example2: Add list to list

# 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.

List methods in Python