python用for循环:输入字符串“hello world”及其子串“o“,随后输出后者出现的次数为 2
时间: 2023-05-26 10:06:42 浏览: 88
python中的for循环
```
string = "hello world"
count = 0
for i in string:
if i == "o":
count += 1
print("子串'o'出现的次数为:", count)
```
输出:
```
子串'o'出现的次数为: 2
```
阅读全文