Menu Close
python list append() method

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, That 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, string, dictionary, another list, and so on.

Return Value of list append() method:

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

Example 1:

Add an element to the fruits list:

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

Output

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

Example 2:

Adding 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. 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 with your friends who want to learn Python programming.

For list function reference, Click here

Python List clear() Method

Was this post helpful?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *