Python/ref list count

来自菜鸟教程
机器人讨论 | 贡献2020年10月29日 (四) 08:49的版本 (机器人:添加分类Python基础教程
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至:导航、​搜索

<languages />

Python List count()方法

❮清单方法

返回值“樱桃”出现在整数中的次数 fruits 列表:

    fruits = ['apple', 'banana', 'cherry']

x = fruits.count("cherry")
  

定义和用法

The count() 方法返回具有指定值的元素数。

句法

list.count(value)
  

参数值

参数 描述
value 需要。任何类型(字符串,数字,列表,元组等)。要搜索的值。

更多例子

返回值9出现在列表中的次数:

    points = [1, 4, 2, 9, 7, 8, 9, 3, 1]

x = points.count(9)
  

❮清单方法