How to find length of list in Python
![](https://pythonpoint.net/wp-content/uploads/2020/11/How-to-find-length-of-list-in-Python-1024x576.jpg)
Finding the length of the list is required in many situations while programming. Don’t worry, python has got your back.
There is a built-in function in python for finding the length of the list – len().
>>>li=[1,2,3,4] >>>len(a) 4
Otherwise, you can use for loop to count the number of elements in the list
li = [ 1 , 2 , 3 , 4 ] #initializing a dummy list count = 0 for item in li: count = count + 1 print ( "Length of the list is " + count )
Programmers always go for len(), since the work can be done in a single line.
Subscribe
Login
Please login to comment
0 Discussion