69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

Python List count()方法

Python List count()方法

Python 列表 ListPython 列表 List

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

 

語法

count()方法語法:

list.count(obj)

 

參數(shù)

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

 

返回值

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

 

實例

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

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 123];

print "Count for 123 : ", aList.count(123);
print "Count for zara : ", aList.count('zara');

以上實例輸出結果如下:

Count for 123 :  2
Count for zara :  1

Python 列表 ListPython 列表 List

下一節(jié):Python List extend()方法

Python 教程

相關文章