Python program to print an Array


The collection of homogenous elements within a single variable and in the contiguous memory location is known as array. The elements in array can be of any datatype but all the elements that are present in the array should be homogeneous, i.e., should belong to the same datatype.

The arrays are a kind of special variables which actually store several values or elements in the name of a single variable with continuous memory locations which are accurately known as “ indices ”.

Indices

The word indices represents the plural form of index. The word index denotes the position of the element within the array. If there are n number of elements within the array, then the position number of an element or the index of an element in the array starts from 0 and continuous up to n – 1. The index of the first element of the array is 0 and the last element of the array is n – 1.

Steps

  • Step 1 − Initially, declare an array with the respective elements or values such that the array size is not exceeded. Note that all the elements that are considered within the array should belong to the same datatype.

  • Step 2 − In order to traverse throughout the array, starting from the first element with the index “ 0 ” to the last element with the index “ n – 1 ”, a loop must be taken in which the loop variable is incremented in each iteration representing the index of the element starting from 0.

  • Step 3 − Within the loop, considering the array with the index “ i ”, print the element in which array[i] represents the element of ith index iteration. This operation must be performed within the loop itself in order to print the element as soon as it is traversed.

Example

In the following example, we are going to learn about the process of printing an array.

arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
size = len(arr)

print("The integral elements present in the array are: ")
for i in range(0, size):
   print(arr[i])

Output

The output for the above program is as follows −

The integral elements present in the array are: 
1
2
3
4
5
6
7
8
9
10

Updated on: 08-May-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements