Counting array elements in Python [duplicate] Ask Question

Counting array elements in Python [duplicate] Ask Question

How can I count the number of elements in an array, because contrary to logic array.count(string) does not count all the elements in the array, it just searches for the number of occurrences of string.

ベストアンサー1

The method len() returns the number of elements in the list.

Syntax:

len(myArray)

Eg:

myArray = [1, 2, 3]
len(myArray)

Output:

3

おすすめ記事