Return the number of times that the string "hi" appears anywhere in the given string
时间: 2024-02-13 07:06:58 浏览: 71
获取字符在字符串中出现的次数
Sure! Here's the Python code to count the number of times the string "hi" appears in a given string:
```python
def count_hi(string):
return string.count("hi")
```
You can call this function with a string argument to get the count of "hi" in that string. For example:
```python
>>> count_hi("hi there hi")
2
>>> count_hi("hiking on a hill")
0
>>> count_hi("hitherehitherehi")
3
```
阅读全文