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
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 - 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. ... Save this answer. ... Show activity on this post. you can use len(arr) as suggested in previous answers to get the length of the array. More on stackoverflow.com
🌐 stackoverflow.com
Creating an array who size and values depend on another array's values being put through a function
Since you mention arrays and arange, I presume you're using Numpy. The way to create one array by applying a function to each element from another array is by using vectorize . More on reddit.com
🌐 r/learnpython
6
18
May 21, 2022
how to write array[1, array.length - 1] in python
Read this: https://stackoverflow.com/questions/509211/understanding-slicing More on reddit.com
🌐 r/learnprogramming
1
0
January 6, 2023
What's the Python equivalent to this pseudo code for Array doubling in Data Structures?
Python is a high level programming language. While it’s possible to use libraries to get something resembling a C-style array, the Python programming language provides the list data-type which is an abstraction over an array that allows you to put arbitrary objects in it (it’s not restricted to a single type), and expand and reduce it dynamically (it handles memory allocation and de-allocation under the hood). The techniques you’re learning about at the moment are useful for understanding how programming works at a low level, but the whole point of a language like Python is that most of those techniques have been implemented for you (generally in quite optimised forms) in data structures that are easier and more pleasant to use while still being reasonably performant. Array doubling is useful because it provides amortised-constant runtime and linear memory usage when you’re wanting to expand a fixed-size array in individual steps, but that’s also what the append method does in Python’s list type. Of course for learning purposes you can just pretend that method doesn’t exist and implement its equivalent with your own code, it’s just good to be aware that when you’re programming in Python that kind of Han handling will generally be handled for you, and you’ll be operating at a more abstract level where you instead focus more on the actual ideas you’re trying to implement. Note that the understanding you’re gaining is valuable though. If you end up working with numerics (e.g. for data analysis or signal processing) then Python’s lists can be inefficient, in which case you’ll likely end up using arrays from the numpy library or DataFrames from the pandas or polars libraries. In those cases the expectation is to know how much data you have in advance, so appending is a linear-time operation that copies all the data to a slightly larger array every time, and is not recommended. More on reddit.com
🌐 r/learnpython
10
1
August 10, 2023
🌐
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.
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.

🌐
IONOS
ionos.com › digital guide › websites › web development › python array length
How to find out a Python array length - IONOS
July 11, 2023 - To use arrays, you need to import other libraries first. In­te­grat­ing 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.
🌐
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.
Find elsewhere
🌐
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.
🌐
AskPython
askpython.com › python › array › array-length-in-python
How to Find the Array Length in Python - AskPython
June 30, 2020 - Python len() method is used to find the length of an array. As we all know, python does not support or provide us with the array data structure in a direct way.
🌐
Python Guides
pythonguides.com › check-the-length-of-an-array-in-python
How To Check The Length Of An Array In Python?
July 22, 2026 - Before listing or approving requests, the script needed to know how many records its array contained. The quickest way to check the length of an array in Python is len(array_name).
🌐
PyTutorial
pytutorial.com › python-array-length-how-to-find-it
PyTutorial | Python Array Length: How to Find It
March 25, 2026 - The len() function is the universal way to get the number of items. It works on any sequence or collection. It is simple and fast. You pass the array or list as the argument. The function returns an 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.
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
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 of elements in an array).
🌐
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).
🌐
FavTutor
favtutor.com › blogs › find-length-of-array-python
How to Find Length of an Array in Python? (5 Best Methods)
September 19, 2022 - For example-: Consider an array of numbers (integers) a = [1, 2, 3, 4, 5] For array a = [1, 'a', 2, 'ab'] -> is invalid However, in the case of lists in Python, b = [1, 2, 3, 4 ] and b = [1, 'a', 2, 'ab'] both are valid. Generally, an array has a fixed size while Lists in Python have dynamic memory space. We can always append (add) or remove elements from a list to change its length, while an array length can not be altered once defined (Again in most languages!).
🌐
Appdividend
appdividend.com › python-array-length
How to Get the Length of an Array in Python
September 7, 2025 - You can use the len() function to determine the length of an array.
🌐
Liberian Geek
liberiangeek.net › home › how-to/tips › get the length of an array in python
Get the Length of an Array in Python | Liberian Geek
June 13, 2026 - Approach 3: Get/Find Array’s ... Method · Approach 6: Get/Find Array’s Length Via “__len__()” Method · The “len()” method is Python’s built-in function that calculates/determines the length of the specific ...
🌐
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 - When using a list or NumPy array ... code. Python makes it easy to calculate the length of any list or array, thanks to the len() method....
🌐
Python Examples
pythonexamples.org › python-array-length
Python - Find Length of Array
In Python, you can find the length of given array using len() built-in function.
🌐
Naiveskill
naiveskill.com › home › determine python array length | complete tutorial with examples in 2023
Determine python array length | Complete tutorial with examples in 2023 - Naiveskill
January 4, 2023 - The syntax for the len() function in Python is as follows: ... where, s is the sequence whose length you want to find. This could be any type of sequence like list, tuple, string, etc.