Categories
Python Answers

How to get the number of elements in a list in Python?

Spread the love

Sometimes, we want to get the number of elements in a list in Python.

In this article, we’ll look at how to get the number of elements in a list in Python.

How to get the number of elements in a list in Python?

To get the number of elements in a list in Python, we use the len function.

For instance, we write

l = len([1, 2, 3])

to get the number of items in the [1, 2, 3] list with len.

It should return 3 since there’re 3 items in the list.

Conclusion

To get the number of elements in a list in Python, we use the len function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *