Python 列表 count() 方法
示例
返回值 "cherry" 在 fruits 列表中出現的次數
fruits = ['apple', 'banana', 'cherry']
x = fruits.count("cherry")
自己動手試一試 »
定義和用法
count() 方法返回具有指定值的元素數量。
語法
list.count(value)
引數值
| 引數 | 描述 |
|---|---|
| value | 必需。任何型別(字串、數字、列表、元組等)。要搜尋的值。 |
返回值 "cherry" 在 fruits 列表中出現的次數
fruits = ['apple', 'banana', 'cherry']
x = fruits.count("cherry")
自己動手試一試 »
count() 方法返回具有指定值的元素數量。
list.count(value)
| 引數 | 描述 |
|---|---|
| value | 必需。任何型別(字串、數字、列表、元組等)。要搜尋的值。 |
如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com
如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com