tripleee
0
Q:

python append to array

x = ['Red', 'Blue']
x.append('Yellow')
22
my_list = [23, 11, 42, 24523]

# append will add it as if you're adding a new list to it
my_list.append([34523, 76979])
print(my_list)

# extend will go over each item in the new source list and add each
# element as part of the target list (my_list)
my_list.extend([12, 99])
print(my_list)

""" 
Output:
[23, 11, 42, 24523, [34523, 76979]]
[23, 11, 42, 24523, [34523, 76979], 12, 99]
"""
4

List = ["One", "value"]

List.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"]
30
my_list = ['geeks', 'for'] 
my_list.append('geeks') 
print my_list 
4
data = []
data.append("Item")

print(data)
1
my_list.extend([1,2,3,4])
my_list
--> [12,1,2,3,4]
2
>>> L = [1, 2, 3, 4]
>>> L.append(5)
>>> L
[1, 2, 3, 4, 5]
1
it=[]
for i in range(10):
  it.append(i)
8

    fruits = ['apple', 'banana', 'cherry']
fruits.append("orange")
   
1
syntax: 
# Each element of an iterable gets appended 
# to my_list
my_list.extend(iterable) 
1

New to Communities?

Join the community