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.
Example 1 – Find Length of 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).
example.py – 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
Example 2 – Find Length of 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().
example.py – 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
Example 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.
example.py – 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.