Google News
logo
Python Program to Access the elements of an array
In Python, arrays are implemented as lists. To access the elements of an array in Python, we can use the same syntax as for accessing the elements of a list.

Here is an example program that demonstrates how to access the elements of an array in Python:
Program :
# create an array
my_array = [1, 2, 3, 4, 5]

# access the first element of the array (index 0)
print(my_array[0])

# access the second element of the array (index 1)
print(my_array[1])

# access the last element of the array (index -1)
print(my_array[-1])
Output :
1
2
5
Note that in Python, the index of the first element of an array is 0, and the index of the last element of an array is `-1`.

We can use positive and negative indices to access the elements of the array from the beginning or the end of the array, respectively.