Open In App

How to Find Length of a list in Python

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The length of a list means the number of elements it contains. In-Built len() function can be used to find the length of an object by passing the object within the parentheses. Here is the Python example to find the length of a list using len().

Python
a1 = [10, 50, 30, 40]
n = len(a1)
print("Size of l1 : ", n)

a2 = []
n = len(a2)
print("Size of l2 : ", n)

a3 = [[10, 20], ["gfg", "courses"], 10.5]
n = len(a3)
print("Size of l3 : ", n)

Different Other Methods for length of a List in Python

Below are other methods to find length of a list in Python

Find the length of a list using the sum() function

Another approach is to use the built-in sum() function in combination with a generator expression. This allows you to find the length of a list by summing the number of elements in the list that meet a certain condition.

Python
l1 = [1, 2, 3, 1, 2, 3]

# find the size of the list
size = sum(1 for num in l1)

# print the size of the list
print(size)

Output
6

Find the length of the list Using For Loop

In this way, we initialize a variable count and then we increment the variable through the loop, and by the end of the loop we get the length of the list in our count variable.

Python
l1 = [1,1,2,5,1,5,2,4,5]

#Intialize a counter to zero
count = 0
for i in l1:
  #Increment the coounter by 1 for each element in the list
  count += 1
print("The length of the l1 is :",count) 

Output
The length of the l1 is : 9

Find the length of the list using the length_hint() method

The length_hint() the function provides a hint about the expected length of an iterable, but it might not be accurate for all types of iterables. Here's your example:

Python
from operator import length_hint

#Intializes a list with several elemnts
l1 = ['Geeks', 'For', 'Geeks']

#Use length_hint to get an estimated length of the list 
size = length_hint(l1)
print('The size of the size l1:',size)

Output
The size of the size l1: 3

Please refer How To Find the Length of a List in Python for more methods and comparison


Practice Tags :

Similar Reads