OneBite.Dev - Coding blog in a bite size

declare an array in python

Code snippet on how to declare an array in python

  my_array = [0, 1, 2, 3, 4, 5] 

This code creates an array called my_array containing the integers from 0 to 5. To create an array in Python, we need to use square brackets and separate each element with a comma. In this example, the list of numbers between 0 and 5 is stored in the my_array array. To access the elements of the array, we can use the index of the elements. For example, to return the element with index 0 (which is the first number in the array) from the my_array array, we type my_array[0]. To access the last element in the array, we can use the -1 index. So the output of my_array[-1] in this example is 5.

python