How to get the length of a list item using for loop in Python; In this tutorial, we will discuss how to get the length of array list using the for a loop.
We will learn how to get the length or size of the list array using the most popular loop method. The for loop iterates through every value in an array item to get the length. Let’s have a look with an example:
How to get list length using For Loop in Python?
We have a list of type array as shown below, to calculate its length we used for loop:
Fruit_List = ['apple', 'banana', 'orange', 'grapes']
list_count = 0;
for fruit in Fruit_List:
list_count += 1
print ("List length count = ", list_count)
#OUTPUT List length count = 4
Using len() function to get the length of the list in Python
Ideally, we can use the len()
function in Python to get the length of list items as shown below:
Fruit_List = ['apple', 'banana', 'orange', 'grapes']
print ("List length count = ", len(Fruit_List))
# OUTPUT List length count = 4
Leave a Reply