list1 = ["One", "value"]
list1.append("to add") # "to add" can also be an int, a foat or whatever"
# list is now ["One", "value","to add"]
#Or
list2 = ["One", "value"]
# "to add" can be any type but IT MUST be in a list
list2 += ["to add"] # can be seen as list2 = list2 + ["to add"]
# list2 is now ["One", "value", "to add"]
# but it have been reconstructed so no side-effects on copied lists will occure
# Add to List
my_list * 2 # [1, 2, '3', True, 1, 2, '3', True]
my_list + [100] # [1, 2, '3', True, 100] --> doesn't mutate original list, creates new one
my_list.append(100) # None --> Mutates original list to [1, 2, '3', True, 100] # Or: <list> += [<el>]
my_list.extend([100, 200]) # None --> Mutates original list to [1, 2, '3', True, 100, 200]
my_list.insert(2, '!!!') # None --> [1, 2, '!!!', '3', True] - Inserts item at index and moves the rest to the right.
' '.join(['Hello','There'])# 'Hello There' --> Joins elements using string as separator.
#.append() is a function that allows you to add values to a list
sampleList.append("Bob")
print ("Bob should appear in the list:", sampleList)
#The output will be:
Bob should appear in the list: ['Bob']
How to append element to a list in Python
# Programming list
programming_list = ['C','C#','Python','Java','JavaScript']
# append the HTML item to the list
programming_list.append('HTML')
print('The new list is :', programming_list)
How to append a list into an existing list
# Programming list
programming_list = ['C','C#','Python','Java']
frontend_programming =['CSS','HTML','JavaScript']
# append the frontend_progamming list into the existing list
programming_list.append(frontend_programming)
# Note that entire list is appended as a single element
print('The new appended list is :', programming_list)