The len() function can be used with several different types in Python - both built-in types and library types. For example:

>>> len([1, 2, 3])
3
Answer from gnud on Stack Overflow
🌐
W3Schools
w3schools.com › python › gloss_python_list_length.asp
Python List Length
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training
🌐
Tutorialspoint
tutorialspoint.com › python › list_len.htm
Python List len() Method
The following example shows the usage of len() method. list1 = [123, 'xyz', 'zara'] list2 = [456, 'abc'] print("First list length : ", len(list1)) print("Second list length : ", len(list2))
Discussions

How do I get the number of elements in a list (length of a list) in Python? - Stack Overflow
For example, both do not allow negative lengths or lengths that exceed a certain value (the sys.maxsize value). So it's always safer to use the len function instead of the __len__ method! ... And for completeness (primarily educational), it is possible without using the len() function. I would not condone this as a good option DO NOT PROGRAM LIKE THIS IN PYTHON, but it serves a purpose for learning algorithms. def count(list... More on stackoverflow.com
🌐 stackoverflow.com
Why can’t we write list.len()?
The len() thing is just a symptom of a larger underlying problem with python. The language provides so many ways of accomplishing the same task that you inevitably end up mixing a bunch of different programming paradigms into the same project. len(list) makes perfect sense in a functional language but in an object oriented language you would want all "list-like" or countable types to inherit from the same parent instead. The _len_() thing is basically an informal interface. Even if you try to remain disciplined in your own code as soon as you start relying on third party libraries that might as well go out the window. I don't think this is solvable, its just a consequence of building a powerful language. More on reddit.com
🌐 r/Python
69
77
February 25, 2016
How to determine the size of all combined elements in a list of lists
This will loop through everything once, but it'll handle any depth (up to recursion limits): from collections.abc import Sequence def len_items(items): """Return the length of all nested iterables.""" return sum( len_items(item) if isinstance(item, Sequence) else 1 for item in items ) More on reddit.com
🌐 r/learnpython
26
70
December 31, 2020
What's the difference between len() and __len__()?

The built-in function len() calls the magic method __len__().

So in your example, there is no difference in the result. It's just that len() is neater.

More on reddit.com
🌐 r/learnpython
10
6
April 19, 2017
🌐
DigitalOcean
digitalocean.com › community › tutorials › find-the-length-of-a-list-in-python
How to find the length of a list in Python | DigitalOcean
July 25, 2025 - How to find the length of a list in Python using the len() function. Includes examples, edge cases, and tips for working with nested or dynamic lists.
Top answer
1 of 11
2991

The len() function can be used with several different types in Python - both built-in types and library types. For example:

>>> len([1, 2, 3])
3
2 of 11
323

How do I get the length of a list?

To find the number of elements in a list, use the builtin function len:

items = []
items.append("apple")
items.append("orange")
items.append("banana")

And now:

len(items)

returns 3.

Explanation

Everything in Python is an object, including lists. All objects have a header of some sort in the C implementation.

Lists and other similar builtin objects with a "size" in Python, in particular, have an attribute called ob_size, where the number of elements in the object is cached. So checking the number of objects in a list is very fast.

But if you're checking if list size is zero or not, don't use len - instead, put the list in a boolean context - it is treated as False if empty, and True if non-empty.

From the docs

len(s)

Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

len is implemented with __len__, from the data model docs:

object.__len__(self)

Called to implement the built-in function len(). Should return the length of the object, an integer >= 0. Also, an object that doesn’t define a __nonzero__() [in Python 2 or __bool__() in Python 3] method and whose __len__() method returns zero is considered to be false in a Boolean context.

And we can also see that __len__ is a method of lists:

items.__len__()

returns 3.

Builtin types you can get the len (length) of

And in fact we see we can get this information for all of the described types:

>>> all(hasattr(cls, '__len__') for cls in (str, bytes, tuple, list, 
                                            range, dict, set, frozenset))
True

Do not use len to test for an empty or nonempty list

To test for a specific length, of course, simply test for equality:

if len(items) == required_length:
    ...

But there's a special case for testing for a zero length list or the inverse. In that case, do not test for equality.

Also, do not do:

if len(items): 
    ...

Instead, simply do:

if items:     # Then we have some items, not empty!
    ...

or

if not items: # Then we have an empty list!
    ...

I explain why here but in short, if items or if not items is more readable and performant than other alternatives.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-find-length-of-list
How To Find the Length of a List in Python - GeeksforGeeks
May 2, 2025 - The length of a list refers to the number of elements in the list. There are several methods to determine the length of a list in Python. For example, consider a list l = [1, 2, 3, 4, 5], length of this list is 5 as it contains 5 elements in it.
🌐
Carmatec
carmatec.com › home › finding the length of a list in python with examples
Finding the Length of a List in Python With Examples
December 31, 2024 - Learn how to find the length of a list in Python using the len() function, with easy-to-follow examples for quick understanding
🌐
freeCodeCamp
freecodecamp.org › news › python-list-length-how-to-get-the-size-of-a-list-in-python
Python List Length – How to Get the Size of a List in Python
March 3, 2022 - The code snippet below shows how to use the len() function to get the length of a list: demoList = ["Python", 1, "JavaScript", True, "HTML", "CSS", 22] sizeOfDemoList = len(demoList) print("The length of the list using the len() method is: " ...
Find elsewhere
🌐
Edureka
edureka.co › blog › python-list-length
How to Get the Length of List in Python? | Edureka
November 27, 2024 - The len() method is one of the easiest ways to find the length of list in Python. This is the most conventional technique adopted by all programmers.
🌐
iO Flood
ioflood.com › blog › python-length-of-list
Finding the Length of a List in Python (With Examples)
August 21, 2024 - In this example, len(empty_list) returns 0. Depending on your program’s requirements, you might want to check if a list is empty before finding its length. Now, let’s take a step back and understand what a list in Python is. A list is a built-in Python data type that can hold different types of items.
🌐
IONOS
ionos.com › digital guide › websites › web development › python list length
How to find the length of a Python list - IONOS
July 18, 2023 - When using the for loop, every element in the list is taken into account. This means that the number of loops counted using the count variable cor­re­sponds to the number of elements within a list. A lesser-known Python function, which is im­ple­ment­ed in an ad­di­tion­al Python module called operator, is length_hint.
🌐
Python Examples
pythonexamples.org › python-list-length
Python List Length - len(list)
Initially, there are four elements in the list. Later we added to elements using list append(). Therefore the final length of the list became six. In this tutorial of Python Examples, we learned how to find length of a given list using len() builtin function.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › how to find length of list in python
How to Find Length of List in Python
June 27, 2025 - The length of a Python list is simply the number of items it contains. For example, a list [1, 2, 3] has a length of 3.
🌐
ReqBin
reqbin.com › code › python › zbhfimqp › python-list-length-example
How do I get the length of a list in Python?
December 22, 2022 - The size of the list is not fixed and changes every time you add or remove items from the list. To get the length of a list in Python, you can use the len() method. An example of getting the length of a Python list using len() function.
🌐
Cherry Servers
cherryservers.com › home › blog › cloud computing › how to get the length of a list in python
How to Get the Length of a List in Python | Cherry Servers
November 7, 2025 - Learn how to get the length of a Python list by using len(), for loop, length_hint(), __len__() methods and NumPy library.
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to find the list length in python
How to Find List Length in Python {3 Methods}
November 27, 2025 - Python offers a built-in method to find the length of a list called len(). This method is the most straightforward and common way to determine a list length. To use the len() function, provide the list as an argument. For example:
🌐
DataCamp
datacamp.com › tutorial › python-list-size
Python List Size: 8 Different Methods for Finding the Length of a List in Python | DataCamp
February 7, 2024 - To find the size of a list in Python using NumPy, we can use the .size attribute as shown below. # Import the NumPy library import numpy as np # Step 1: Convert the list into a NumPy array my_array = np.array(my_list) # Step 2: Use the 'size' attribute of the NumPy array to find its size array_size = my_array.size # Print out the size of the array (which is the same as the length of the list) print(array_size) # Output will be 4
🌐
MonoVM
monovm.com › 🐍 python 🐍 › determining list length in python | methods & examples
Determining List Length in Python | Methods & Examples
November 7, 2023 - This method is widely used in Python programming for its simplicity and speed. Using `len()` can significantly reduce the amount of code you need to write compared to the Naïve Counter Method. Here's how to use the `len()` function to find the length of a list: Syntax: The `len()` function takes a single argument, which is the list you want to measure. It returns the number of elements in the list. Example: Let's take a look at a Python code example to see how to use `len()`:
🌐
Scaler
scaler.com › home › topics › python length of list
Python Length of List - Scaler Topics
May 4, 2023 - This variable is incremented when an element is added to the list and is decremented when an element is removed. Let us take an example of a list and find its length using the length_hint() function
🌐
Hostman
hostman.com › tutorials › how to get the length of a list in python
How to Find the Length of a List in Python: Quick Guide | Hostman
July 17, 2025 - Country_list = ["The United States of America", "Cyprus", "Netherlands", "Germany"] count = len(Country_list) print("There are", count, "countries") ... You can determine a list’s length in Python with a for loop.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Cisco
ipcisco.com › home › python list length
Python List Length | How To Use Python Length() Method ⋆
March 19, 2021 - Here, we will use the belowm python code: list = [15, "cats", 63, "dogs"] length = len(list) print(length) As a return fom this code, we will receive 4. Because there are 4 members of this mixed list.