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

0 votes

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

arr.__len__()

If so, why the strange syntax?

Oct 8, 2018 in Python by ana1504.k
• 7,870 points
72 views

1 answer to this question.

0 votes
my_list = [1,2,3,4,5,6,7]
len(my_list)
# 7
The same works for tuples:

my_tuple = (1,2,3,4,5,6,7)
len(my_tuple)
# 7
And strings, which are really just arrays of characters:

my_string = 'hello world'
len(my_string)
answered Oct 8, 2018 by SDeb
• 13,180 points

Related Questions In Python

0 votes
1 answer

What is the preferred way to concatenate strings in python??

If the strings you are concatenating are ...READ MORE

answered Dec 20, 2018 in Python by charlie_brown
• 7,720 points
95 views
0 votes
1 answer

how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE

answered Mar 12 in Python by Mohammad
• 3,060 points
55 views
+4 votes
7 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 330 views
0 votes
1 answer

What is the purpose of inner class in Python?

Advantages of inner class: Logical grouping of classes: ...READ MORE

answered Feb 7 in Python by SDeb
• 13,180 points
265 views
0 votes
1 answer

How to check the version of Python?

you can check the version of python ...READ MORE

answered Sep 25, 2018 in Python by SDeb
• 13,180 points
60 views