add new item in array in python
Code snippet on how to add new item in array in python
arr = [1,3,5,7]
arr.append(9)
print(arr)
This code adds an item (in this case, 9) to an array (in this case, arr). First, the array containing the items 1, 3, 5, 7 is defined on the first line (arr = [1,3,5,7]). On the second line, the append() function is used to add the item 9 to the array (arr.append(9)). Finally, the array is printed on the third line to show that the item has been successfully added (print(arr)). The output of this code will be ‘[1, 3, 5, 7, 9]’, indicating that the item 9 has been added to the array.