my_list = [1,2,3,4,5]
len(my_list)
# 5

The same works for tuples:

my_tuple = (1,2,3,4,5)
len(my_tuple)
# 5

And strings, which are really just arrays of characters:

my_string = 'hello world'
len(my_string)
# 11

It was intentionally done this way so that lists, tuples and other container types or iterables didn't all need to explicitly implement a public .length() method, instead you can just check the len() of anything that implements the 'magic' __len__() method.

Sure, this may seem redundant, but length checking implementations can vary considerably, even within the same language. It's not uncommon to see one collection type use a .length() method while another type uses a .length property, while yet another uses .count(). Having a language-level keyword unifies the entry point for all these types. So even objects you may not consider to be lists of elements could still be length-checked. This includes strings, queues, trees, etc.

The functional nature of len() also lends itself well to functional styles of programming.

lengths = map(len, list_of_containers)
Answer from Soviut on Stack Overflow
🌐
W3Schools
w3schools.com › python › gloss_python_array_length.asp
Python Array Length
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... Use the len() method to return the length of an array (the number of elements in an array)....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-array-length
Python Array length - GeeksforGeeks
July 23, 2025 - Finding the length of an array in Python means determining how many elements are present in the array. For example, given an array like [1, 2, 3, 4, 5], you might want to calculate the length, which is 5.
🌐
Flexiple
flexiple.com › python › length-of-array-python
Python Array Length - How to Calculate the Length of an Array in Python - Flexiple - Flexiple
It is a direct way to measure the size of an array without needing to iterate through each element. For example, consider an array of integers: numbers = [1, 2, 3, 4, 5]. To find the length of this array, you would use the len() function as follows:
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python array length
Python Array Length | Working of len() in Python with Examples
May 13, 2024 - This is a guide to Python Array Length. Here we discuss working of the len() in python to calculate the total number of items present in the given array along with examples and its code implementation.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
IONOS
ionos.com › digital guide › websites › web development › python array length
How to find out a Python array length - IONOS
July 11, 2023 - Integrating NumPy into your project will allow you to use Python arrays. To find out the number of elements in your array, you can use the native Python len function. In the following example, we’ll create an array that contains the numbers 0 to 5.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to get array length in python
How to Get Array Length in Python - Spark By {Examples}
May 31, 2024 - Python language doesn’t have a built-in array data type but you can use the list, array module, and the NumPy module to represent the arrays. In this article, I will explain how to get the length of an array in Python using the len() function, as ...
Top answer
1 of 8
1261
my_list = [1,2,3,4,5]
len(my_list)
# 5

The same works for tuples:

my_tuple = (1,2,3,4,5)
len(my_tuple)
# 5

And strings, which are really just arrays of characters:

my_string = 'hello world'
len(my_string)
# 11

It was intentionally done this way so that lists, tuples and other container types or iterables didn't all need to explicitly implement a public .length() method, instead you can just check the len() of anything that implements the 'magic' __len__() method.

Sure, this may seem redundant, but length checking implementations can vary considerably, even within the same language. It's not uncommon to see one collection type use a .length() method while another type uses a .length property, while yet another uses .count(). Having a language-level keyword unifies the entry point for all these types. So even objects you may not consider to be lists of elements could still be length-checked. This includes strings, queues, trees, etc.

The functional nature of len() also lends itself well to functional styles of programming.

lengths = map(len, list_of_containers)
2 of 8
54

The way you take a length of anything for which that makes sense (a list, dictionary, tuple, string, ...) is to call len on it.

l = [1,2,3,4]
s = 'abcde'
len(l) #returns 4
len(s) #returns 5

The reason for the "strange" syntax is that internally python translates len(object) into object.__len__(). This applies to any object. So, if you are defining some class and it makes sense for it to have a length, just define a __len__() method on it and then one can call len on those instances.

🌐
iO Flood
ioflood.com › blog › get-length-of-array-in-python-guide-and-examples
Get Length of Array in Python: Guide and Examples
March 12, 2024 - Suppose we have the following array: ... Running this code will output 5, which represents the number of elements in the array. The len() function is a powerful and handy tool in Python.
Find elsewhere
🌐
Java Code Geeks
examples.javacodegeeks.com › home › web development › python
Python Array length - Java Code Geeks
July 28, 2023 - The len() function takes an iterable as an argument and returns the number of elements in it. # Example array my_array = [1, 2, 3, 4, 5] # Finding the length of the array using len() function array_length = len(my_array) print("Array length:", ...
🌐
CodeGym
codegym.cc › java blog › learning python › length of an array in python
Length of an Array in Python
November 7, 2024 - For our purposes today, we'll mostly be talking about lists, but don't worry—the techniques we'll discuss will work for both! The simplest way to find the length of an array (or list) in Python is by using the len() function.
🌐
AskPython
askpython.com › home › how to find the array length in python
How to Find the Array Length in Python - AskPython
April 3, 2023 - import array as A arr = A.array('i',[1,2,3,4,5]) print("Array elements: ",arr) print("Length of array: ",len(arr)) ... As we all know, we can create an array using NumPy module and use it for any mathematical purpose.
🌐
Scaler
scaler.com › home › topics › length of array in python
Length of array in Python - Scaler Topics
May 25, 2022 - Length of an array is the number of elements present in the array. In python, the length of an array is the highest index of an array + 1.
🌐
Medium
medium.com › @alizek433 › python-array-length-5302bb9d7aa2
Python Array Length. Python Array Length: | by Alize Khan | Medium
February 2, 2024 - You pass the value of the element being searched as the argument to the method, and the element’s index number is returned. ... The len() function in Python can be used to find the length of an array.
🌐
Edureka
edureka.co › blog › arrays-in-python
Arrays in Python: What are Python Arrays & How to use them? | Edureka
November 27, 2024 - There are many operations that can be performed on arrays which are as follows – · Length of an array is the number of elements that are actually present in an array. You can make use of len() function to achieve this.
🌐
Pierian Training
pieriantraining.com › home › python numpy tutorial: get length of array in python
Python NumPy Tutorial: Get Length of Array in Python - Pierian Training
April 27, 2023 - In this example, we created a one-dimensional NumPy array called `arr` and then used its `size` attribute to get the total number of elements in the array. Since `arr` has five elements, its size is also `5`. In conclusion, there are three ways ...
🌐
Udacity
udacity.com › blog › 2021 › 10 › how-to-calculate-the-length-of-an-array-in-python.html
How to calculate the length of an array in Python? | Udacity
October 20, 2021 - Take a look at how this works: phrase = "Hello, World!" print("This phrase contains", len(phrase), "characters.") ... This phrase contains 13 characters. This article explored lists, arrays, and NumPy arrays in Python and the benefits of each.
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
An array can hold many values under a single name, and you can access the values by referring to an index number. You refer to an array element by referring to the index number. ... Use the len() method to return the length of an array (the number ...
🌐
Replit
replit.com › home › discover › how to find the length of an array in python
How to find the length of an array in Python | Replit
While len() is almost always your best bet, exploring other methods can help you understand how Python works with data structures. numbers = [10, 20, 30, 40, 50] count = 0 for _ in numbers: count += 1 print(f"Length calculated manually: ...