append value in python list code example

Example 1: how to add an item to a list in python

myList = [1, 2, 3]

myList.append(4)

Example 2: append to list python

list = ["a"]
list.append("b")

print(list)
["a","b"]

Example 3: python append to list

stuff = ["apple", "banana"]
stuff.append("carrot")
# Print to see if it worked
print(stuff)
# You can do it with a variable too
whatever = "pineapple"
stuff.append(whatever)
# Print it again
print(stuff)

Example 4: append python

it=[]
for i in range(10):
  it.append(i)

Example 5: add an element to list python

a=[8,5,6,1,7]
a.append(9)

Example 6: append a list to another list as element

a = ['Jon', 'janni', 'Jannardhan']
b = ['28', '29', '30']
a.append(b)
print(a)
a.pop()
a.extend(b)
print(a)