KuLdi Lakh
0
Q:

python add to list

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

myList.append(4)
6
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
food = "banana"
basket = []

basket.append(food)
0
# to add an item to a list
list.append(item)

# To extend an list with a new list
list1.extend(list2)
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