How do I get the number of elements in a list (length of a list) in Python?

Better Stack Team
Updated on February 2, 2023

To get the number of elements in a list in Python, you can use the len() function.

For example, if you have a list my_list, you can get its length using len(my_list).

Here's an example:

 
my_list = [1, 2, 3, 4, 5]
list_length = len(my_list)
print(list_length)  # Output: 5

This would output 5, which is the number of elements in the list.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack