python append example

Example 1: add something to list python

#append to list
lst = [1, 2, 3]
something = 4
lst.append(something)
#lst is now [1, 2, 3, 4]

Example 2: 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 3: append python

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

Example 4: append python

EmptyList = []

EmptyList.append('This list is')
EmptyList.append('no longer empty')

print(EmptyList)