In this tutorial, we will see how to count items inlist in python
Count total items in the list
You can use len()
function to count items in the list.
Let’s understand with the help of example.
1 2 3 4 5 6 |
list1=[1,2,3,4] print("List:",list1) length=len(list1) print("Length of list1",length) |
Output:
List: [1, 2, 3, 4]
Length of list1: 4
Count occurence of each element in the list
1 2 3 4 5 |
list1=[1,2,3,4,1,4,3,2,2,1,5] print("List:",list1) print("Count of 2 in list1:",list1.count(2)) |
Output:
List: [1, 2, 3, 4, 1, 4, 3, 2, 2, 1, 5]
Count of 2 in list1 3
That’s all about Python count items in the list.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.