In Python, lists can be used as arrays, because the language doesn’t have built-in support. An array is one chunk of memory that usually consists of multiple elements, where a list is a list of objects where one element points to another and it doesn’t have to be inside one block of memory.
You can simulate an array by changing an element with the index number.
array = ['A', 'B', 'C', 'D', 'E'] array = 'X' array = 'Y' array = 'Z' print(array)
['A', 'X', 'Y', 'Z', 'E']
Append an element to an array
To add a new element to an array, use the append function.
array = ['A', 'B', 'C', 'D', 'E'] array.append('X') array.append('Y') array.append('Z') print(array)
['A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z']