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)....
🌐
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.

🌐
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
3 weeks ago - Because Python uses zero-based indexing, a list with five elements has indices from 0 to 4. Trying to access an element at the index equal to the length—for example, my_list[5]—will fail because that index doesn't exist. Always remember that the last valid index in an array is len(array) - 1.
🌐
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.
🌐
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....
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
Consider the following example of a 3x4 matrix implemented as a list of 3 lists of length 4:
🌐
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 - The most direct, efficient, and “Pythonic” way to get the number of items in a list is by using Python’s built-in len() function. This function is a core part of the language and is designed to be highly optimized for this exact purpose. The len() function is universal and can be used ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-arrays
Python Arrays - GeeksforGeeks
2 weeks ago - In Python, array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. Unlike Python lists (can store elements of mixed types), arrays must have all elements of same type. Having only homogeneous elements makes it memory-efficient.
🌐
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).
🌐
Real Python
realpython.com › len-python-function
Using the len() Function in Python – Real Python
November 16, 2024 - The function is efficient because it typically retrieves the length from an attribute stored within the object. How can I use len() with different data types in Python?Show/Hide · You can use len() with several built-in data types, including strings, lists, tuples, dictionaries, sets, and range objects. Additionally, len() can be used with third-party data types like NumPy arrays and pandas DataFrames.
🌐
Wyzant
wyzant.com › resources › ask an expert
Getting the length of an array in Python | Wyzant Ask An Expert
May 16, 2018 - Number 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 · Upvote • 0 Downvote · Add comment · More · Report · Ask a question for free · Get a free answer to a quick problem.
🌐
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 - How to get the length of an array in Python? You can get the length of an array using the built-in len() function. The array is a collection of items of
🌐
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.
🌐
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 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
2 weeks ago - They always set the value after normalization, so length always ends as an integer. ... The term array-like object refers to any object that doesn't throw during the length conversion process described above. In practice, such object is expected to actually have a length property and to have ...
🌐
IONOS
ionos.com › digital guide › websites › web development › python list length
How to find the length of a Python list - IONOS
July 18, 2023 - The most popular way to find out a Python list length is to use the Python len function. This is defined for sequences, such as lists, and collection types. It can also be used to find out one-dimensional Python array lengths.
🌐
TutorialsPoint
tutorialspoint.com › return-the-length-of-a-string-array-element-wise-in-python
Return the length of a string array element-wise in Python
February 24, 2022 - import numpy as np # Create a ... in the Array...\n",arr.size) # To return the length of a string array element-wise, use the numpy.char.str_len() method in Python Numpy # The method returns an output array of integers....
🌐
CodeGym
codegym.cc › java blog › learning python › length of an array in python
Length of an Array in Python
November 7, 2024 - You can use the built-in len() function to easily find the length of a list, numpy array, or array from the array module. Alternatively, you can write your own function using a for loop to count the elements manually.