list add list python code example

Example 1: python add to list

list_to_add.append(item_to_add)

Example 2: python how to add to a list

food = "banana"
basket = []

basket.append(food)

Example 3: python add to list

# Statically defined list
my_list = [2, 5, 6]
# Appending using slice assignment
my_list[len(my_list):] = [5]  # [2, 5, 6, 5]
# Appending using append()
my_list.append(9)  # [2, 5, 6, 5, 9]
# Appending using extend()
my_list.extend([-4])  # [2, 5, 6, 5, 9, -4]
# Appending using insert()
my_list.insert(len(my_list), 3)  # [2, 5, 6, 5, 9, -4, 3]

Example 4: add list python

my_list = ['a', 'b', 'c']
my_list.append('e')
print(my_list)
# Output
#['a', 'b', 'c', 'e']

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

a=[1,2,3,4]

a+=[5,6]

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

myList = []
myList.append(value_to_add)