user5186
0
Q:

how do i add to a list in python

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

myList.append(4)
6
list_to_add.append(item_to_add)
# or
list_to_add.push(item_to_add)
5
#!/usr/bin/env python

# simple.py

nums = [1, 2, 3, 4, 5]

nums.append(6)
2
a=[1,2,3,4]

a+=[5,6]
1
#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
numbers = [1, 2, 3, 4]
numbers.append(10)
print(numbers)
1
food = "banana"
basket = []

basket.append(food)
0
a=[8,5,6,1,7]
a.append(9)
1

New to Communities?

Join the community