Q:

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

belongs to collection: Python Array Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

Output:

Number of elements present in given array: 5

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python program to print the sum of all elements in... >>
<< Python program to print the smallest element in an...