DekGenius.com
PYTHON
append element to an array python
x = ['Red', 'Blue']
x.append('Yellow')
python add element to array
my_list = []
my_list.append(12)
append item to array python
data = []
data.append("Item")
print(data)
python array append
my_list = ['a','b']
my_list.append('c')
print(my_list) # ['a','b','c']
other_list = [1,2]
my_list.append(other_list)
print(my_list) # ['a','b','c',[1,2]]
my_list.extend(other_list)
print(my_list) # ['a','b','c',[1,2],1,2]
how to push item to array python
mylist = list()
mylist.append(1)
mylist.append(2)
mylist.append(3)
print(mylist)
>>> [1,2,3]
append element an array in python
my_input = ['Engineering', 'Medical']
my_input.append('Science')
print(my_input)
python array append array
a = [1, 2, 3]
b = [10, 20]
a.append(b) # Output: [1, 2, 3, [10, 20]]
a.extend(b) # Output: [1, 2, 3, 10, 20]
python array append array
a = [1, 2, 3]
b = [10, 20]
a = a + b # Create a new list a+b and assign back to a.
print a
# [1, 2, 3, 10, 20]
# Equivalently:
a = [1, 2, 3]
b = [10, 20]
a += b
print a
# [1, 2, 3, 10, 20]
© 2022 Copyright:
DekGenius.com