There's no mention of numpy in the question. If by array you mean list, then if you treat a list as a boolean it will yield True if it has items and False if it's empty.

l = []

if l:
    print "list has items"

if not l:
    print "list is empty"
Answer from John Kugelman on Stack Overflow
🌐
W3Schools
w3schools.com › python › gloss_python_array_length.asp
Python Array Length
Python Examples Python Compiler ... ... Use the len() method to return the length of an array (the number of elements in an array). ... Note: The length of an array is always one more than the highest array index...
🌐
Python Guides
pythonguides.com › check-if-string-length-is-greater-than-0-in-python
How To Check If String Length Is Greater Than 0 In Python?
March 19, 2025 - The most easy way to check if a string’s length is greater than 0 is by using Python’s built-in len() function.
🌐
Flexiple
flexiple.com › python › length-of-array-python
Python Array Length - How to Calculate the Length of an Array in Python - Flexiple - Flexiple
Learn how to calculate Python array length using the len() function, Numpy, and array module, with practical examples and differences between arrays and lists.
🌐
GeeksforGeeks
geeksforgeeks.org › python-array-length
Python Array length - GeeksforGeeks
May 8, 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.
🌐
Stack Overflow
stackoverflow.com › questions › 66306119 › python-array-length-shorter-than-declared
Python array length shorter than declared - Stack Overflow
0 How to solve python limited array length · 0 Why is an int in a list and in an compact array the same size? (24bytes) 0 numpy array bigger than python list · 0 How does len(array) work under the hood · 1 Why is Python's 'len' function exaggerating the length of an array of bytes?
Find elsewhere
🌐
PythonHow
pythonhow.com › how › check-if-a-list-is-empty
Here is how to check if a list is empty in Python
# Define a list my_list = [] # Check if the list is empty if len(my_list) == 0: print("The list is empty.") else: print("The list is not empty.") ... The list is empty. ... To check if a list is empty in Python, you can use the len() function to check the length of the list.
🌐
Edureka
edureka.co › blog › arrays-in-python
Arrays in Python: What are Python Arrays & How to use them? | Edureka
November 27, 2024 - To access array elements, you need to specify the index values. Indexing starts at 0 and not from 1. Hence, the index number is always 1 less than the length of the array.
🌐
GeeksforGeeks
geeksforgeeks.org › length-of-longest-subarray-with-product-greater-than-or-equal-to-0
Length of longest subarray with product greater than or equal to 0 - GeeksforGeeks
April 12, 2021 - Keep updating the length of the subarray for each negative element found in the array. The value of L is the length of longest subarray with product greater than equals to 0.
🌐
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 - While __len__() accomplishes the same job as len(), it’s less commonly employed in Python code due to its decreased readability. As such, it’s generally recommended to use len() instead. An alternative method to calculate the length of an array involves using a for loop to iterate over the array and count the number of elements. Here’s an illustration: array = [1, 2, 3, 4, 5] count = 0 for element in array: count += 1 print(count)
🌐
IONOS
ionos.com › digital guide › websites › web development › python array length
How to find out a Python array length - IONOS
July 11, 2023 - If you work with NumPy, the library also has a way to find out Python array length. It’s called size and is defined only for arrays, meaning if you want to use it for Python lists, it won’t work. Unlike with len, when you use size, you can also find out the number of elements in a multidimensional array. To give you a better idea of how to use size, we’ll give you a code example. First, we’ll create the same array as in the example above, which contains the numbers 0 to 5 and saves the variable l as length.
🌐
Reddit
reddit.com › r/learnpython › array length
r/learnpython on Reddit: Array length
August 14, 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!

🌐
Codecademy
codecademy.com › forum_questions › 521be7a080ff33604400099c
Why i<array.length rather than i=array.length | Codecademy
When using length to determine the upper bound, make your operator ‘less than’, not ‘less than or equal to’. No point in referencing an array or string element that does not exist. 0 to 9 gives 10 elements.
🌐
Real Python
realpython.com › len-python-function
Using the len() Function in Python – Real Python
November 16, 2024 - Therefore, len() returns 0. In contrast, the variable second_string does include the letter Y, and so both the string and the object of type YString are truthy. You can read more about using object-oriented programming and defining classes in Object-Oriented Programming (OOP) in Python. ... You’ve explored how to use len() to determine the number of items in sequences, collections, and other data types that hold several items at a time, such as NumPy arrays and pandas DataFrames.
🌐
GitHub
github.com › duckdb › duckdb › issues › 2916
array_slice returns empty when the end index is greater than the length of array · Issue #2916 · duckdb/duckdb
October 10, 2021 - array_slice returns empty when the end index is greater than the length of array. Other implementations of array slicing (like in python, postgres) just slice till the end of the array.
Published   Jan 12, 2022
🌐
Python
docs.python.org › 3 › library › array.html
array — Efficient arrays of numeric values
This is occasionally useful when working with low-level (and inherently unsafe) I/O interfaces that require memory addresses, such as certain ioctl() operations. The returned numbers are valid as long as the array exists and no length-changing operations are applied to it.
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.