Latest web development tutorials

Python3 List count()方法

Python3 列表 Python3列表


描述

count() 方法用於統計某個元素在列表中出現的次數。

語法

count()方法語法:

list.count(obj)

參數

  • obj -- 列表中統計的對象。

返回值

返回元素在列表中出現的次數。

實例

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

#!/usr/bin/python3

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

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

以上實例輸出結果如下:

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

Python3 列表 Python3列表