In this Python tutorial, you will learn how to find the length of a given list using len() built-in function.

Python List Length

To find the length of a Python List, you can use Python built-in function len().

len() accepts Python List as an argument and returns an integer representing number of elements in the list.

Examples

ADVERTISEMENT

1. Find length of a List

In the following python program, we initialize a python list with integers and find the length of the list (number of elements in the list).

Python Program

#initialize list
aList = [21, 28, 14, 96, 84, 65, 74, 31]

#find list length
len = len(aList)

#print list length
print('Length of the list is :', len)
Try Online

Output

Length of the list is : 8

Reference tutorials for the above program

2. Find length of a List with elements of different datatypes

In the following example, we initialize a list with different datatypes and try to find the length of the list using len().

Although the type of the elements does not matter in finding the length of a list, this example must be telling you the same.

Python Program

#initialize list
aList = [True, 28, 'Tiger']

#find list length
len = len(aList)

#print list length
print('Length of the list is :', len)
Try Online

Output

Length of the list is : 3

3. Find length of an empty List

Of course, the length of an empty list is zero. But we are finding that out programmatically in the following example.

Python Program

#empty list
aList = []

#find list length
len = len(aList)

#print list length
print('Length of the list is :', len)
Try Online

Output

Length of the list is : 0

Conclusion

In this Python Tutorial, we learned how to find the length of a list using len() function with the help of example Python programs.