append in array python code example

Example 1: append element to an array python

x = ['Red', 'Blue']
x.append('Yellow')

Example 2: append python

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"]

Example 3: python add element to array

my_list = []

my_list.append(12)

Example 4: append object python

>>> L = [1, 2, 3, 4]
>>> L.append(5)
>>> L
[1, 2, 3, 4, 5]

Example 5: add to python list

array.append(element)

Example 6: append a list to another list as element

a = ['Jon', 'janni', 'Jannardhan']
b = ['28', '29', '30']
a.append(b)
print(a)
a.pop()
a.extend(b)
print(a)

Tags:

Misc Example