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 Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... Use the len() method to return the length of an array ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-array-length
Python Array length - GeeksforGeeks
July 23, 2025 - You can get the length by capturing the last index it provides. You must start from 1 to match the actual count. ... Explanation: enumerate(a, 1) loop through the list a with a counter starting at 1. Although the loop does nothing (pass), the ...
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
Why is getting the length of an array O(1) and not O(n)?
Most implementations store the length of an array in the object itself. Whenever you insert/remove it gets updated. Thus you're not iterating to get the length you're just getting a value. More on reddit.com
🌐 r/learnprogramming
45
11
November 7, 2022
How do I find the length (or dimensions, size) of a numpy matrix in python? - Stack Overflow
It actually works differently than ... for a 2D python array, as this would return 2. So, is there a more intuitive way to find the size of a matrix, or is this the best I have? ... First result for numpy dimensions btw, try the search box ... ... Thanks for pointing me to that question! I did try searching, but "numpy matrix dimensions" (or length or size for ... More on stackoverflow.com
🌐 stackoverflow.com
Array length
It's ordered that way because that's the nature of a linked list. Usually, each element of a linked list consists of more than just the pointer to the next element in the list. You'll usually see linked lists used when new elements might be picked up or dropped from a list at any time, there is a need to be able to traverse the list, insertion or deletion is "expensive" (e.g., time-consuming), and the items being stored don't need to be stored in order in one big chunk of memory. It's just faster to include a pointer to the next element as part of the structure than to shuffle everything around whenever an insertion or deletion is needed. I suspect that this linked list consists of nothing but that pointer so that you can learn the nature of linked lists without being distracted by any additional overhead in each element in the list that you don't need to consider. Did that answer your question, or do you still have questions? More on reddit.com
🌐 r/learnpython
4
1
November 16, 2022
🌐
CodeGym
codegym.cc › java blog › learning python › length of an array in python
Length of an Array in Python
November 7, 2024 - The len() function counts the number of elements in the list or array and returns that value. ... Pretty straightforward, right? You simply pass the array or list to len(), and it gives you the count of elements.
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.

🌐
Scaler
scaler.com › home › topics › length of array in python
Length of array in Python - Scaler Topics
May 25, 2022 - We can use Python's len() function to find the length of an array.
Find elsewhere
🌐
IONOS
ionos.com › digital guide › websites › web development › python array length
How to find out a Python array length - IONOS
July 11, 2023 - 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. Using len ensures that the length of our Python array will be assigned ...
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
Note: The length of an array is always one more than the highest array index.
🌐
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.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.1 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
RunxBuild
runxbuild.com › home › blog › python array length: len is the answer, and python lists are not arrays
Python Array Length: len Is the Answer, and Python Lists Are Not Arrays
July 18, 2026 - Get the length of a Python array or list with len(). It is O(1), works on lists, strings, tuples, and dicts - and Python lists are not really arrays. Here is why.
🌐
Python
docs.python.org › 3 › library › array.html
array — Efficient arrays of numeric values
3 weeks ago - The typecode character used to create the array. ... The length in bytes of one array item in the internal representation.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.6.dev0 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.5 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
Reddit
reddit.com › r/learnpython › array length
r/learnpython on Reddit: Array length
November 16, 2022 -

A non-empty array A consisting of N integers is given.

Array A represents a linked list. A list is constructed from this array as follows:

the first node (the head) is located at index 0;
the value of a node located at index K is A[K];
if the value of a node is −1 then it is the last node of the list;
otherwise, the successor of a node located at index K is located at index A[K] (you can assume that A[K] is a valid index, that is 0 ≤ A[K] < N).

For example, for array A such that:

A[0] = 1 A[1] = 4 A[2] = -1 A[3] = 3 A[4] = 2

📷

the following list is constructed:

the first node (the head) is located at index 0 and has a value of 1;
the second node is located at index 1 and has a value of 4;
the third node is located at index 4 and has a value of 2;
the fourth node is located at index 2 and has a value of −1.

Write a function:

def solution(A)

that, given a non-empty array A consisting of N integers, returns the length of the list constructed from A in the above manner.

For example, given array A such that:

A[0] = 1 A[1] = 4 A[2] = -1 A[3] = 3 A[4] = 2

the function should return 4, as explained in the example above.

Assume that:

N is an integer within the range [1..200,000];
each element of array A is an integer within the range [−1..N-1];
it will always be possible to construct the list and its length will be finite.

I read this question and still don't understand why the order of list in that way. Would you please explain? Could not post a photo here to make it easier to understand. Thank you so much!

🌐
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.
🌐
Start Coder
startcoder.com › courses › python › length and the last element
Finding Array Length | Start Coder
For this, we use the len() function, which returns the number of elements in the array. The len() function is used similarly to the print() function, so we place the array whose length we want to find out in the parentheses.
🌐
Towards AI
pub.towardsai.net › find-the-length-of-an-array-in-python-83511cb611ce
Find the Length of an Array in Python | by Towards AI Editorial Team | Towards AI
September 27, 2022 - So, we will not be using any Python libraries in the implementation. Please let us know if you have any suggestions or comments. Let’s get started! You are given an array arr of n elements. Your goal is to find the length n of the array without using any inbuilt functions like len().