How to Find the Length of the List in Python | Python Program

In this article, we will learn to find the length of the list using the python program.

We find the length of the list using two methods:

1. Using loops
2. Using the len() function

Using loop

Explanation

1. We make a variable count, that store the number of the elements present in the list.
2. Then, we iterate the list and update the count by +1.
3. And lastly, we print the length of the list.

Program

 1 2 3 4 5 6 7 8 9 10 11 12 13 # list list = [1, 2, 3, 4, 5, 6, 7, 8, 9] # count variable to count the number of the elements present in the list count = 0 # iterate the list for i in list: # update the value of the count by +1 count +=1 # print the length of the list print("The length of the list is: ",count)

Output

The length of the list is:  9

Using len() function

Explanation

1. By using len(name_of_list) function we easily find the length of the given list.
2. And lastly, we print the length of the list.

Program

 1 2 3 4 5 6 7 8 # list list = [1, 2, 3, 4, 5, 6, 7, 8, 9] # use len() function to find the length of the list length = len(list) # print the length of the list print("The length of the list is: ",length)

Output

The length of the list is:  9

No Comment