how to append a value in list in python code example

Example 1: how to append a number to a list in python

l = [1, 2, 4, 5] 
new_item = 6
l.append(6)
print(l)

Example 2: how do i add to a list in python

a=[1,2,3,4]

a+=[5,6]

Example 3: how to add values to a list in python

myList = []
myList.append(value_to_add)

Example 4: append to lists python

list = ['a', 'b', 'c', 'd']
  print list[1:-1]   ## ['b', 'c']
  list[0:2] = 'z'    ## replace ['a', 'b'] with ['z']
  print list         ## ['z', 'c', 'd']

Tags:

Misc Example