Python program to print length of an array(list)

In this tutorial, we will learn writing the python program to create an array (list in case of python) and print the length (number of elements stored) in the array (list).

Problem Statement

For the given array, our program should return the length of the array as an output.

For example:

[elementor-template id=”5257″]

Case 1: if the given the array (list) is [1, 2, 3, 4].

               The output should be 4.

Case 2: if the given array (list) is [9, 8, 7, 6, 5].

                The output should be 5.

Our logic to print length of an array(list)

  • Our program will use len() built-in function to calculate the length and print the output.

[elementor-template id=”5253″]

Algorithm to print length of an array(list)

Step 1: Start

Step 2: perform len() operation on given list

Step 3: print the value of ‘len(arr)’.

Step 4: Stop

Python code to print length of an array(list)

[elementor-template id=”5256″]

Output 1:

Explanation:

For the given array (list) [1, 2, 3, 4, 5], the len() function will calculates the length of the array (list) passed as an argument in len() function, the len() function will return the length of array (list) in ‘int’ data type.

In this example, the given array (list) is passed as the parameter of the len() function, so the len() function returned the size of the array (list).