list append python 3 code example

Example 1: add item to list python

list.append(item)

Example 2: append to list python

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

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

Example 3: how to append list in python

list1 = ["hello"]
list1 = list1 + ["world"]

Example 4: python list append

# Python list mutation, adding elements
history = ["when"]

# adds item to the end of a list
history.append("how")
# ["when", "how"]

# combine lists
history.extend( ["what", "why"] ) # works with tuples too
# or
history = history + ["what", "why"]
# ["when", "how", "what", "why"]

# insert at target position
history.insert(3, "where")
# ["when", "how, "what", "where", "why"]
#

Example 5: using append in python

lst=[1,2,3,4]
print(lst)

#prints [1,2,3,4]

lst.append(5)
print(lst)

#prints [1,2,3,4,5]

Example 6: list append python 3

#!/usr/bin/python3

list1 = ['C++', 'Java', 'Python']
list1.append('C#')
print ("updated list : ", list1)