在Python中,`count` 是一个内置函数,用于统计序列(如列表、元组或字符串)中某个元素出现的次数。以下是 `count` 函数的基本用法:
```python
sequence.count(element)
其中:`sequence` 是要搜索的序列(列表、元组或字符串)。`element` 是要统计出现次数的元素。例如,在列表中统计某个元素出现的次数:```pythonfruits = ['苹果', '西瓜', '水蜜桃', '西瓜', '雪梨']
count = fruits.count('西瓜')
print(count) 输出:2
在字符串中统计某个子串出现的次数,可以指定开始和结束位置:
```python
text = "hello world"
substring = "world"
count = text.count(substring, start=0, end=5)
print(count) 输出:1
`count` 函数返回一个整数,表示指定元素在序列中出现的次数

