Contents
Python List.append()
Python List append() method appends element to the end of this list.
The syntax to use append() function to add element at the end of the list is
myList.append(element)
append() method modifies the source list.
append() method returns None.
Examples
1. Append item 98 to the given list
In the following program, we define a list of elements [52, 41, 63]
. Then, we append an element 98
to this list using append() method.
Python Program
myList = [52, 41, 63]
myList.append(98)
print(myList)
Run Code Online Output
[52, 41, 63, 98]
2. Append another list to this list
You can use append() function to append another list of element to this list.
In the following program, we shall use for loop to iterate over elements of second list and append each of these elements to the first list.
Python Program
list_1 = [52, 41, 63]
list_2 = [47, 27, 97]
for element in list_2:
list_1.append(element)
print(list_1)
Run Code Online Output
[52, 41, 63, 47, 27, 97]
Summary
In this tutorial of Python Examples, we learned how to use List.append() method to append an element to the list.
⫷ Previous tutorialNext tutorial ⫸