Python program to print the elements of an array

python tutorials and learn python

Created with Sketch.

Python program to print the elements of an array

This is a simple program to create an array and then to print it’s all elements.

Now, just know about arrays.

Arrays are the special variables that store multiple values under the same name in the contiguous memory allocation. Elements of the array can be accessed through their indexes.

 

Here, 1, 2, 3, 4 and 5 represent the elements of the array. These elements can be accessed through their corresponding indexes, 1.e., 0, 1, 2, 3 and 4.

ALGORITHM:

  • STEP 1: Declare and initialize an array.
  • STEP 2: Loop through the array by incrementing the value of i.
  • STEP 3: Finally, print out each element of the array.

PROGRAM:

  1. #Initialize array   
  2. arr = [12345];
  3. print(“Elements of given array: “);
  4. #Loop through the array by incrementing the value of i   
  5. for i in range(0, len(arr)):
  6.     print(arr[i]),

Output:

Elements of given array:
1	2    3    4    5

Leave a Reply

Your email address will not be published. Required fields are marked *