Program to print the number of elements present in an Array in Python

Program to print the number of elements present in an Array in Python. This function uses array initialisation, inbuilt function and print statement. This is for beginners, class 11,12 and B Tech computer science students.

Program to print the number of elements present in an Array

What is an Array ?

A Python Array is a collection of common type of data structures having elements with same data type. It is used to store collections of data.

How will be the length of Array will be calculated ?

By using inbuilt function len(a) which delivers the length of array a. The array named as a is enclosed in the bracket of inbuilt funtion len which will give its length. Fist the array will be initialised and then calculated by this function.

Source code :

arr = [1, 2, 3, 4, 5];     
     
print("Number of elements present in given array: " ,len(arr));

Source code Explanation :

step 1:Initialize array
arr = [1, 2, 3, 4, 5];
step 2:Number of elements present in an array can be found using len()
print(“Number of elements present in given array: ” ,len(arr));

Output :

== RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/y.py ==
Number of elements present in given array:  5
>>> 

Output Explanation :

== RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/y.py ==
Number of elements present in given array: 5
>>>

The program is restarted. The len(arr) gives the lenngth which is 5 in this cae with the print statement showing “Number of elements present in given array: 5”.

Conclusion:

The program is running fine.

Thank you for reading, learning and downloading Program to print the number of elements present in an Array in Python. This function uses array initialisation, inbuilt function and print statement. This is for beginners, class 11,12 and B Tech computer science students. Below are the links to the program with the same level of difficulty, practical file for class 11,12 and pythons projects.click below:
/category/python-programs/
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 *