append() method in Python Lists can be used to append an element at the end of the list. This element can be of any type like integer, string, boolean, list etc.
The append() method modifies the specified list by adding the element at the end of the list, however, it does returns ‘None’ value in all cases.
Syntax
list.append(item)
item: element to be added
l = [1, 3, 5, 2, 8, 3]
print(l.append(10)) // returns 'None'
print(l) // returns modified list
O/P
None
[1, 3, 5, 2, 8, 3, 10]
Program: Take 5 values as input and append it to a list
# Take 5 values as input and append it to a list
# defining list as l
l = []
print('Enter 5 elements : ')
for i in range(1, 6):
# taking elements one by one
n = int(input())
# using append method to add element to our list
l.append(n)
print("List : ", l)
O/P
Enter 5 elements :
3
4
1
4
6
List : [3, 4, 1, 4, 6]
That’s all here.
