Python3 列表 Python3 列表


描述

count() 方法用于統(tǒng)計某個元素在列表中出現(xiàn)的次數(shù)。

語法

count()方法語法:

list.count(obj)

參數(shù)

  • obj -- 列表中統(tǒng)計的對象。

返回值

返回元素在列表中出現(xiàn)的次數(shù)。

實例

以下實例展示了 count()函數(shù)的使用方法:

#!/usr/bin/python3

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

print ("123 元素個數(shù) : ", aList.count(123))
print ("W3CSchool 元素個數(shù) : ", aList.count('W3CSchool'))

以上實例輸出結(jié)果如下:

123 元素個數(shù) :  2
W3CSchool 元素個數(shù) :  1

Python3 列表 Python3 列表