How to get size of a list in python?

0 votes
110 views
asked Aug 6, 2016 by Hitesh Garg (132 points)  

I have a list and have added some objects to it. But I am not able to find any method(using the dot(.) operator) that could return the length of the created list. I have created the list like below.

employee = ["name", 25, "company", 120000]

Now how do i get the length of this list called 'employees'?

1 Answer

0 votes
answered Sep 5, 2016 by Rahul Singh (163 points)  

In python list has no method to find the length. Rather we use general method len() available to find length of vaious types.

# Lenth of list
x = ["name", 25, "company", 120000]
print(len(x))
# Lenth of String
y = "names"
print(len(y))
# Lenth of tuple
z = ("name", 25, "company", 120000, 46578, "test")
print(len(z))

output of above program is -

4
5
6

Link of the sample

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...