Python List append() Method
Python List append() Method
The list.append() method in Python adds or appends an item to the end of the list.
Syntax
list.append(x)
Parameter
x: It is a required parameter that represents an element of any type (string, number, object etc.).
Example 1
# Python program explaining # the list.append() method week_list = ["Monday", "Tuesday", "Wednesday","Thursday","Friday", "Saturday"] print("List before calling append() method\n", week_list) # appending sunday at the end of the list week_list.append("Sunday") print("List after calling append() method") print(week_list)
Output
List before calling append() method ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] List after calling append() method ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
Example 2
# Python program explaining # the list.append() method str_list = ['The even number', 'are:'] num_list = [2, 4, 6, 8,10] str_list.append(num_list) print (str_list)
Output
['The even number', 'are:', [2, 4, 6, 8, 10]]