How to Get the Length of a Python List?

Find out how to get the total number of elements in a python list

To get the length/size of a list in Python, we can simply use the built-in len() function like so:

list = []

print(len(list)) # output: 3

The len() function takes an object as an argument and returns the total number of items (i.e. the length of the object). It has the following syntax:


Since a list in Python is an object, the len() function works for it and returns the total number of items in the list.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.