Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (11.4k 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 (106k 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:-

Learn more about Python from an expert. Enroll in our Python Course

Browse Categories

...