Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 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:-

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

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...