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
🌐
FavTutor
favtutor.com › blogs › find-length-of-array-python
How to Find Length of an Array in Python? (5 Best Methods)
September 19, 2022 - Hence, the last index of an array = length of array - 1 · In Python, an array is not an in-built data type.
🌐
Medium
medium.com › @alizek433 › python-array-length-5302bb9d7aa2
Python Array Length. Python Array Length: | by Alize Khan | Medium
February 2, 2024 - 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.
Discussions

Is arr.__len__() the preferred way to get the length of an array in Python? - Stack Overflow
Internally, python will then try to call the special __len__ method of the object that was passed. ... you can use len(arr) as suggested in previous answers to get the length of the array. More on stackoverflow.com
🌐 stackoverflow.com
[Python] How to find the length of elements in a list?
Try if len(element) == 2: len returns the number of elements in a list, when applied to a string it returns the number of characters. More on reddit.com
🌐 r/learnprogramming
2
0
November 23, 2016
Help with optimizing fixed-length array code
I seemingly avoided all the lengthy array extensions by initialising an array with the fixed size Growing a list isn't really a problem complexity-wise. It takes amortized O(1) time. Sure, allocating the right number of elements right from the start will save you some constant overhead, but it won't improve the complexity. And for algorithm challenges, you'll usually want to improve the complexity, not the constant factors. Is there something hidden that takes computation time, or a way to optimize it that i do not know? What's taking time is moving (potentially) every element of your array in your insert and delete functions. That's not really hidden though, it's right there in the loops. Inserting into and deleting from sorted arrays, while keeping them sorted, are inherently O(n) operations. You really don't want to use arrays/lists for something like this. If you want a sorted data structure that stays sorted when inserting into and deleting from it, you'll usually want to go for trees. More on reddit.com
🌐 r/learnpython
6
2
May 2, 2024
I've been told this is how you get the array length
I knew someone who genuinely did this to compute an array’s length in Java and he was trying to persuade us that it was faster than just doing “array.length”… More on reddit.com
🌐 r/ProgrammerHumor
119
1738
April 17, 2022
🌐
CodeCombat
discourse.codecombat.com › t › difference-between-len-and-array-length › 21308
Difference between len() and array.length -
April 30, 2020 - They are both methods of returning a count of something. This something can be the count of characters in a string, or the number of elements in an array. Which one you use is dependent on the coding language you are using. For example: · But I saw array.length in python as well, it’s also ...
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.

🌐
Towards AI
towardsai.net › home › publication › programming › find the length of an array in python
Find the Length of an Array in Python | Towards AI
March 22, 2022 - Now, take some time to understand the problem and implement it in Python. First of all, we are creating a function find_len(arr). The function takes an array arr as an argument. Our goal is to find the length of the array arr.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Get the dimensions, shape, and size of an array | note.nkmk.me
April 23, 2025 - You can get the number of dimensions, the shape (length of each dimension), and the size (total number of elements) of a NumPy array (numpy.ndarray) using the ndim, shape, and size attributes. The bui ...
Find elsewhere
🌐
DEV Community
dev.to › hrishikesh1990 › how-to-calculate-the-length-of-an-array-in-python-2mng
How to calculate the length of an array in Python? - DEV Community
April 13, 2022 - To find the length of an array in Python, we can use the len() function. It is a built-in Python method that takes an array as an argument and returns the number of elements in the array.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to get numpy array length
How to Get NumPy Array Length - Spark By {Examples}
March 27, 2024 - You can find the length of a NumPy array using the built-in len() function in Python, which returns the number of elements in the first dimension of the array.
🌐
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)....
🌐
Wyzant
wyzant.com › resources › ask an expert
Getting the length of an array in Python | Wyzant Ask An Expert
May 16, 2018 - In Python, is the following the ... 1 Python Tutor in Wyzant · About this tutor › · About this tutor › · a= [1,2,3,4,5] len(a) is giving you the length of the list ·...
🌐
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.
🌐
Cach3
w3schools.com.cach3.com › python › gloss_python_array_length.asp.html
Python Array Length
Python Examples Python Exercises Python Quiz Python Certificate ... Use the len() method to return the length of an array (the number of elements in an array).
🌐
NumPy
numpy.org › doc › stable › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.4 Manual
NumPy (Numerical Python) is an open source Python library that’s widely used in science and engineering. The NumPy library contains multidimensional array data structures, such as the homogeneous, N-dimensional ndarray, and a large library of functions that operate efficiently on these data ...
🌐
Liberian Geek
liberiangeek.net › home › how-to/tips › how to get/find length of an array in python?
How to Get/Find Length of an Array in Python? | Liberian Geek
December 27, 2023 - To get the array’s length, use the “len()” method, “length_hint()” method, “__len__()” method, “.size” or “.shape” attribute of NumPy library or “for” loop.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › web development › python
Python Array length - Java Code Geeks
July 28, 2023 - Knowing the length of an array ... tasks. You can use the len() function for general arrays and lists or opt for the numpy library for advanced numerical operations and multi-dimensional arrays....
🌐
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 - In Python, the length of the array is computed using the len() function, which returns the integer value consisting of the number of elements or items present in the given array, known as array length in Python.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
AskPython
askpython.com › home › how to find the array length in python
How to Find the Array Length in Python - AskPython
April 3, 2023 - Python len() method enables us to find the total number of elements in an array. It returns the count of the elements in an array. ... Here, the array can be any type of array for which we want to find the length.
🌐
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 - The simplest way to determine the length of an array in Python is by using the built-in len() function. Simply pass the array as an argument to the function like so: length = len(array).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
4 weeks ago - Other methods (e.g., push(), splice(), etc.) also result in updates to an array's length property. ... When setting a property on a JavaScript array when the property is a valid array index and that index is outside the current bounds of the array, the engine will update the array's length property accordingly: