Python 列表 count() 方法
实例
返回值“cherry”出现在fruits列表中的次数:
fruits = ['apple', 'banana', 'cherry']
x = fruits.count("cherry")
运行示例»定义和用法
count()方法返回具有指定值的元素数。
语法
list.count(value)
参数值
| Parameter | Description |
|---|---|
| value | 必须项。指定检索的值 |
fruits列表中的次数:
fruits = ['apple', 'banana', 'cherry']
x = fruits.count("cherry")
运行示例»count()方法返回具有指定值的元素数。
| Parameter | Description |
|---|---|
| value | 必须项。指定检索的值 |