How to Add or Append Element to Python List?

In this tutorial, you will learn how you can add or append elements to a Python list.

Python List append() method

The append() method adds an item to the end of the Python list.

Syntax of the append() method

This method takes only one parameter, which is a value to be inserted into the list, and the value can be of any type, such as – string, number, list, etc.

list.append(value)

This method does not return any value, it only updates the existing list.

>>> a = [21, 78, 52]
>>> a.append('Python')
>>> print(a)
[21, 78, 52, 'Python']
>>>

Python add list to list

As we already know that the append method can add any type of value to a Python list, so you can add a list to a list using the append method.

>>> a = [12, 54, 'Python']
>>> b = [1, 2, 3]
>>> a.append(b)
>>> print(a)
[12, 54, 'Python', [1, 2, 3]]
>>>

Leave a Reply

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