Is arr.__len__() the preferred way to get the length of an array in Python?

前端 未结 8 1023
悲哀的现实
悲哀的现实 2020-12-04 05:18

In Python, is the following the only way to get the number of elements?

arr.__len__()

If so, why the strange syntax?

8条回答
  •  难免孤独
    2020-12-04 05:37

    you can use len(arr) as suggested in previous answers to get the length of the array. In case you want the dimensions of a 2D array you could use arr.shape returns height and width

提交回复
热议问题