我有一个多行字符串:
Str1 = """I thought a thought.
But the thought I thought
Wasn’t the thought I thought I thought.
If the thought I thought I thought,
Had been the thought I thought ."""
从给定的多行字符串中,给出未使用内置函数时单词“the”出现的次数
发布于 2021-04-19 19:57:01
print(Str1.count('thought'))
就这样。
如果你正计划做一件事,你可以用“思想”这个词
count = 0
for n in Str1.split():
if 'thought' in n:
count += 1
print(count)
https://stackoverflow.com/questions/67161507
复制相似问题