Menu Close
python list append() method

In this tutorial, you will learn about the Python list append() method. append method() method in Python allow us to insert a new item at the end of the existing list.
In the previous tutorial, we have seen about Python list with an appropriate example.

Python List append() method:

In Python, the python list append() method is used to add a new item at the end of the existing list. append in list Python is a built-in function, Which means you don’t need to install any external package to use the append method in Python.

Syntax of Append Function:

The syntax of append in Python is.

list.append(item)

Python List append() method parameter:

list append method in Python takes a single parameter That is called item.
item:- An item to be added to the end of the list.
The item can be numbers, strings, dictionaries, another list, and so on.

Return Value of list append() method:

list append method in Python does not return any value ( Return None ).

Example

Add an element to the fruits list:


fruits = ['apple', 'banana', 'cherry']
fruits.append("orange")
print(fruits)

Output

['apple', 'banana', 'cherry', 'orange']

Example:

Add dictionary to the fruits list.


fruits = ['apple', 'banana', 'cherry']
car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

fruits.append(car)
print(fruits)
fruits.clear()
print(fruits)

Output

['apple', 'banana', 'cherry', {'brand': 'Ford', 'model': 'Mustang', 'year': 1964}]

Conclusion

In this tutorial, you have learned the Python list append method. The python list append() method is used to add new items to the end of the list. Item can be anything like numbers, string, dictionary in fact you can add another list to the existing list.

If you like this post please comment and share it with your friends who want to learn Python programming.

For list function reference, Click here

Python List count() Method
Python List Sort Method

Related Posts