Python program to print the number of elements present in an array

Created with Sketch.

Python program to print the number of elements present in an array

In this program, we need to count and print the number of elements present in the array.

Some elements present in the array can be found by calculating the length of the array.

 

Length of above array is 5. Hence, the number of elements present in the array is 5.

ALGORITHM:

  • STEP 1: Declare and initialize an array.
  • STEP 2: Calculate the length of the array that is a number of elements present in the array.
  • STEP 3: An in-built function can calculate length.
  • STEP 4: Finally, print the length of the array.

Array in Python is declared as

Arrayname = [ele1, ele2, ele3,….]
len() method returns the length of the array in Python.


PROGRAM:

  1. #Initialize array   
  2. arr = [12345];
  3. #Number of elements present in an array can be found using len()  
  4. print(“Number of elements present in given array: “ + str(len(arr)));

Output:

Number of elements present in given array: 5

Leave a Reply

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