Count list elements in Python

Count elements in list

>>> myList=[8, 2, 3, 6, 8]
>>> len(myList)
5

Count the occurrences of a given item in the list

>>> myList=["a","a","a","b","c","c"]
>>> myList.count('a')
3

Test if a given value is in the list

>>> myList=[10,20,30,40,50]
>>> 25 in myList
False

See also


Last update : 10/17/2021