1#append to list
2lst = [1, 2, 3]
3something = 4
4lst.append(something)
5#lst is now [1, 2, 3, 4]
1my_list = []
2item1 = "test1"
3my_list.append(item1)
4
5print(my_list)
6# prints the list ["test1"]
1# Basic syntax:
2your_list.append('element_to_append')
3
4# Example usage:
5your_list = ['a', 'b']
6your_list.append('c')
7print(your_list)
8--> ['a', 'b', 'c']
9
10# Note, .append() changes the list directly and doesn’t require an
11# assignment operation. In fact, the following would produce an error:
12your_list = your_list.append('c')
1my_list = ['a', 'b', 'c']
2my_list.append('e')
3print(my_list)
4# Output
5#['a', 'b', 'c', 'e']