0 votes
1 view
in Python by (11.5k points)

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

arr.__len__()

If so, why the strange syntax?

1 Answer

0 votes
by (107k points)
edited by
  • You can use the following way for getting the length of an array in Python

my_list = [1,2,3,4,5]

len(my_list)

    image

  • So instead of arr.__len__() you can use:-

import array

arr = array.array('i')

arr.append('2')  

len(arr)

    image

To know more about this you can have a look at the following video tutorial:-

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...