Categories
Python Answers

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

Spread the love

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

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

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

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

For instance, we write:

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

We call len with a list as its argument to return the number of items in the list and assign that to l.

Therefore, l is 3.

Conclusion

To get the number of elements in a list with Python, we can 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 *