Python List – append()

Python list.append(element) method appends the given element at the end of the list.

Append operation modifies the original list, and increases the length of the list by 1.

Append operation is same as the insert operation at the end of the list.

Syntax

The syntax to call append() method on a list myList is

myList.append(element)

where

  • myList is a Python list
  • append is method name
  • element is the object or value that has to be appended to the list
ADVERTISEMENT

Examples

Append Element to List

In the following program, we initialize a list myList with some elements, and append an element 'mango' to the end of the list.

main.py

#initialize list
myList = ['apple', 'banana', 'cherry']

#append 'mango' to myList
myList.append('mango')

#print list
print(f'resulting list : {myList}')
Try Online

Output

resulting list : ['apple', 'banana', 'cherry', 'mango']

Append Item to an Empty List

Now, we shall take an empty list in myList, and append an element 'mango' to this empty list.

main.py

#initialize list
myList = []

#append 'mango' to myList
myList.append('mango')

#print list
print(f'resulting list : {myList}')
Try Online

Output

resulting list : ['mango']

Conclusion

In this Python Tutorial, we learned how to append an element to the list using list.append() method.