Latest web development tutorials

Python3 List count () method

Python3 list Python3 list


description

count () method is used to count the number of times an element that appears in the list.

grammar

count () method syntax:

list.count(obj)

parameter

  • obj - the list of objects of the statistics.

return value

Returns the number of elements appear in the list.

Examples

The following example shows the count () function to use:

#!/usr/bin/python3

aList = [123, 'Google', 'w3big', 'Taobao', 123];

print ("123 元素个数 : ", aList.count(123))
print ("w3big 元素个数 : ", aList.count('w3big'))

Examples of the above output results are as follows:

123 元素个数 :  2
w3big 元素个数 :  1

Python3 list Python3 list