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,910 points
963 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,300 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 21, 2018 in Python by charlie_brown
• 7,720 points
845 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, 2019 in Python by Mohammad
• 3,230 points
1,227 views
+4 votes
7 answers
0 votes
2 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
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, 2019 in Python by SDeb
• 13,300 points
2,334 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,300 points
807 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP