add an element to the end of an array in python

To add an element to the end of an array in Python, you can use the append() method. Here's an example:

main.py
my_array = [1, 2, 3, 4]
my_array.append(5)
print(my_array)  # Output: [1, 2, 3, 4, 5]
86 chars
4 lines

In this example, we create a list called my_array with the values [1, 2, 3, 4]. We then use the append() method to add the value 5 to the end of the list. The resulting list is [1, 2, 3, 4, 5].

related categories

gistlibby LogSnag