add an element to the end of a list python code example
Example 1: python add to list
list_to_add.append(item_to_add)
Example 2: append to lists python
list = ['larry', 'curly', 'moe']
list.append('shemp') ## append elem at end
list.insert(0, 'xxx') ## insert elem at index 0
list.extend(['yyy', 'zzz']) ## add list of elems at end
print list ## ['xxx', 'larry', 'curly', 'moe', 'shemp', 'yyy', 'zzz']
print list.index('curly') ## 2
list.remove('curly') ## search and remove that element
list.pop(1) ## removes and returns 'larry'
print list ## ['xxx', 'moe', 'shemp', 'yyy', 'zzz']
Example 3: append to lists python
list = [] ## Start as the empty list
list.append('a') ## Use append() to add elements
list.append('b')
Example 4: add an element to list python
a=[8,5,6,1,7]
a.append(9)