0
Q:

python how to add to a list

list_to_add.append(item_to_add)
40
myList = [1, 2, 3]

myList.append(4)
6
my_list = []
item1 = "test1"
my_list.append(item1)

print(my_list) 
# prints the list ["test1"]
5
list_to_add.append(item_to_add)
# or
list_to_add.push(item_to_add)
5
a=[1,2,3,4]

a+=[5,6]
1
numbers = [1, 2, 3, 4]
numbers.append(10)
print(numbers)
1
food = "banana"
basket = []

basket.append(food)
0
#append to list
lst = [1, 2, 3]
li = 4
lst.append(li)
#lst is now [1, 2, 3, 4]

.append("the add"): append the object to the end of the list.
.insert("the add"): inserts the object before the given index.
.extend("the add"): extends the list by appending elements from the iterable.
0
a=[8,5,6,1,7]
a.append(9)
1

New to Communities?

Join the community