Program to print the elements of an Array in Python

Program to print the elements of an Array in Python. This program contains initialization of Array and for loop iterative statement. This program is for Beginners, class 11, 12 and B Tech Computer science student.

Program to print the elements of an Array

What is an Array?

This is a simple program to create an array and then to print it’s all elements. 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.

Python program to print the elements of an array

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.

Source code :

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

Source code explanation:

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

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: C:/csstudy/source code file 2/Program to print the elements of an Array in Python.py 
Elements of given array: 
1
2
3
4
5
>>> 

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license()” for more information.

RESTART: C:/csstudy/source code file 2/Program to print the elements of an Array in Python.py
Elements of given array:
1
2
3
4
5

Output Explanation :

Here the elements of Array is shown.

Conclusion:

The program runs fine.

Thank you for reading, learning and downloading source code of Program to print the elements of an Array in Python. This program contains initialization of Array and for loop iterative statement. This program is for Beginners, class 11, 12 and Btech Computer science student. There is more programs in the link provide below :
Python Programs Archives – CS Study
Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study
Computer Science Practical file for class 12 Term-2 – CS Study
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

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