Python Array Length: Using len() Function

You can use the built-in function len() to get the number of elements in an array (or list) in Python. Here is an example code:

my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print("数组元素个数为:", length)

In this example, we have defined a list named my_list with five elements. We then used the len() function to obtain the number of elements in the list and stored the result in a variable called length. Finally, we printed out the number of elements in the list.

You can use the len() function to get the number of elements in any iterable object, whether it’s an array, list, or any other type.

bannerAds